@addozhang/dsh-discord 0.1.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/LICENSE +21 -0
- package/README.md +68 -0
- package/cordis.patch.yml +14 -0
- package/lib/client/DiscordSettingsCard.d.ts +6 -0
- package/lib/client/PluginCard.d.ts +43 -0
- package/lib/client/card-controller.d.ts +22 -0
- package/lib/client/card-form.d.ts +111 -0
- package/lib/client/fields.d.ts +50 -0
- package/lib/client/index.d.ts +12 -0
- package/lib/client/nav-icon.d.ts +21 -0
- package/lib/client/settings-model.d.ts +49 -0
- package/lib/client/slot-contract.d.ts +57 -0
- package/lib/client/snapshot-store.d.ts +9 -0
- package/lib/client.js +1622 -0
- package/lib/compose.d.ts +158 -0
- package/lib/compose.js +227 -0
- package/lib/credential.d.ts +20 -0
- package/lib/credential.js +24 -0
- package/lib/discord/commands.d.ts +45 -0
- package/lib/discord/commands.js +87 -0
- package/lib/discord/components.d.ts +29 -0
- package/lib/discord/components.js +57 -0
- package/lib/discord/delivery.d.ts +21 -0
- package/lib/discord/delivery.js +31 -0
- package/lib/discord/interaction-lifecycle.d.ts +42 -0
- package/lib/discord/interaction-lifecycle.js +78 -0
- package/lib/discord/rest.d.ts +74 -0
- package/lib/discord/rest.js +149 -0
- package/lib/discord/selector.d.ts +39 -0
- package/lib/discord/selector.js +70 -0
- package/lib/discord/thread-port.d.ts +37 -0
- package/lib/discord/thread-port.js +58 -0
- package/lib/dsh/api-proxy-face.d.ts +253 -0
- package/lib/dsh/api-proxy-face.js +370 -0
- package/lib/features/adapter-status.d.ts +111 -0
- package/lib/features/adapter-status.js +103 -0
- package/lib/features/approval-expiry.d.ts +27 -0
- package/lib/features/approval-expiry.js +36 -0
- package/lib/features/approval-routing.d.ts +50 -0
- package/lib/features/approval-routing.js +57 -0
- package/lib/features/approval-store.d.ts +86 -0
- package/lib/features/approval-store.js +119 -0
- package/lib/features/approval-view.d.ts +47 -0
- package/lib/features/approval-view.js +48 -0
- package/lib/features/ask-wiring.d.ts +74 -0
- package/lib/features/ask-wiring.js +151 -0
- package/lib/features/host-status.d.ts +41 -0
- package/lib/features/host-status.js +24 -0
- package/lib/features/image-collection.d.ts +56 -0
- package/lib/features/image-collection.js +79 -0
- package/lib/features/image-download.d.ts +48 -0
- package/lib/features/image-download.js +77 -0
- package/lib/features/image-submission.d.ts +67 -0
- package/lib/features/image-submission.js +57 -0
- package/lib/features/interaction-router.d.ts +84 -0
- package/lib/features/interaction-router.js +655 -0
- package/lib/features/model-control.d.ts +79 -0
- package/lib/features/model-control.js +51 -0
- package/lib/features/preset-control.d.ts +84 -0
- package/lib/features/preset-control.js +43 -0
- package/lib/features/project-bind.d.ts +69 -0
- package/lib/features/project-bind.js +57 -0
- package/lib/features/project-info.d.ts +25 -0
- package/lib/features/project-info.js +22 -0
- package/lib/features/project-list.d.ts +79 -0
- package/lib/features/project-list.js +93 -0
- package/lib/features/prompt-submission.d.ts +53 -0
- package/lib/features/prompt-submission.js +47 -0
- package/lib/features/question-expiry.d.ts +53 -0
- package/lib/features/question-expiry.js +56 -0
- package/lib/features/question-routing.d.ts +108 -0
- package/lib/features/question-routing.js +162 -0
- package/lib/features/question-store.d.ts +124 -0
- package/lib/features/question-store.js +186 -0
- package/lib/features/question-view.d.ts +58 -0
- package/lib/features/question-view.js +81 -0
- package/lib/features/queue-control.d.ts +63 -0
- package/lib/features/queue-control.js +31 -0
- package/lib/features/reconcile-bindings.d.ts +75 -0
- package/lib/features/reconcile-bindings.js +54 -0
- package/lib/features/reconcile-deliveries.d.ts +29 -0
- package/lib/features/reconcile-deliveries.js +28 -0
- package/lib/features/reconcile-events.d.ts +49 -0
- package/lib/features/reconcile-events.js +50 -0
- package/lib/features/reconcile-intents.d.ts +32 -0
- package/lib/features/reconcile-intents.js +32 -0
- package/lib/features/reconcile-interactions.d.ts +59 -0
- package/lib/features/reconcile-interactions.js +54 -0
- package/lib/features/session-adopt.d.ts +89 -0
- package/lib/features/session-adopt.js +77 -0
- package/lib/features/session-creation.d.ts +49 -0
- package/lib/features/session-creation.js +43 -0
- package/lib/features/session-mainline.d.ts +75 -0
- package/lib/features/session-mainline.js +96 -0
- package/lib/features/session-resume.d.ts +44 -0
- package/lib/features/session-resume.js +40 -0
- package/lib/features/skill-run.d.ts +48 -0
- package/lib/features/skill-run.js +25 -0
- package/lib/features/steer-control.d.ts +37 -0
- package/lib/features/steer-control.js +28 -0
- package/lib/features/stop-control.d.ts +38 -0
- package/lib/features/stop-control.js +31 -0
- package/lib/features/task-admission.d.ts +29 -0
- package/lib/features/task-admission.js +21 -0
- package/lib/features/thread-continuation.d.ts +36 -0
- package/lib/features/thread-continuation.js +18 -0
- package/lib/features/thread-creation.d.ts +81 -0
- package/lib/features/thread-creation.js +81 -0
- package/lib/features/thread-routing.d.ts +49 -0
- package/lib/features/thread-routing.js +34 -0
- package/lib/features/turn-ownership.d.ts +39 -0
- package/lib/features/turn-ownership.js +40 -0
- package/lib/features/unbound-mention.d.ts +49 -0
- package/lib/features/unbound-mention.js +31 -0
- package/lib/features/workspace-channel.d.ts +41 -0
- package/lib/features/workspace-channel.js +47 -0
- package/lib/gateway/gateway.d.ts +50 -0
- package/lib/gateway/gateway.js +229 -0
- package/lib/gateway/inbound.d.ts +85 -0
- package/lib/gateway/inbound.js +186 -0
- package/lib/gateway/ingress.d.ts +15 -0
- package/lib/gateway/ingress.js +22 -0
- package/lib/i18n.d.ts +92 -0
- package/lib/i18n.js +180 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +869 -0
- package/lib/lifecycle.d.ts +44 -0
- package/lib/lifecycle.js +84 -0
- package/lib/policy/authorization.d.ts +41 -0
- package/lib/policy/authorization.js +64 -0
- package/lib/policy/disclosure.d.ts +93 -0
- package/lib/policy/disclosure.js +153 -0
- package/lib/policy/guard.d.ts +31 -0
- package/lib/policy/guard.js +46 -0
- package/lib/policy/suppress.d.ts +13 -0
- package/lib/policy/suppress.js +20 -0
- package/lib/settings-namespace.d.ts +7 -0
- package/lib/settings-namespace.js +6 -0
- package/lib/settings.d.ts +37 -0
- package/lib/settings.js +102 -0
- package/lib/startup.d.ts +16 -0
- package/lib/startup.js +60 -0
- package/lib/state/bindings.d.ts +46 -0
- package/lib/state/bindings.js +55 -0
- package/lib/state/channel-bindings.d.ts +37 -0
- package/lib/state/channel-bindings.js +43 -0
- package/lib/state/domain.d.ts +82 -0
- package/lib/state/domain.js +86 -0
- package/lib/state/effect-machine.d.ts +37 -0
- package/lib/state/effect-machine.js +52 -0
- package/lib/state/fail-closed.d.ts +44 -0
- package/lib/state/fail-closed.js +57 -0
- package/lib/state/intents.d.ts +51 -0
- package/lib/state/intents.js +73 -0
- package/lib/state/records.d.ts +37 -0
- package/lib/state/records.js +30 -0
- package/lib/state/retention.d.ts +74 -0
- package/lib/state/retention.js +68 -0
- package/lib/state/session-owners.d.ts +50 -0
- package/lib/state/session-owners.js +50 -0
- package/lib/stream/finalizer.d.ts +49 -0
- package/lib/stream/finalizer.js +67 -0
- package/lib/stream/icons.d.ts +15 -0
- package/lib/stream/icons.js +36 -0
- package/lib/stream/live.d.ts +140 -0
- package/lib/stream/live.js +515 -0
- package/lib/stream/markdown.d.ts +24 -0
- package/lib/stream/markdown.js +95 -0
- package/lib/stream/outbound.d.ts +27 -0
- package/lib/stream/outbound.js +25 -0
- package/lib/stream/render-fence.d.ts +27 -0
- package/lib/stream/render-fence.js +37 -0
- package/lib/stream/render-model.d.ts +48 -0
- package/lib/stream/render-model.js +68 -0
- package/lib/stream/splitter.d.ts +8 -0
- package/lib/stream/splitter.js +58 -0
- package/lib/stream/tool-view.d.ts +40 -0
- package/lib/stream/tool-view.js +39 -0
- package/lib/stream/typing.d.ts +22 -0
- package/lib/stream/typing.js +58 -0
- package/lib/stream/update-scheduler.d.ts +20 -0
- package/lib/stream/update-scheduler.js +65 -0
- package/package.json +86 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1622 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@addozhang/dsh-discord",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
"use strict";
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name2 in all)
|
|
13
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/client/index.ts
|
|
26
|
+
var index_exports = {};
|
|
27
|
+
__export(index_exports, {
|
|
28
|
+
apply: () => apply,
|
|
29
|
+
inject: () => inject,
|
|
30
|
+
name: () => name
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
|
|
34
|
+
// src/features/adapter-status.ts
|
|
35
|
+
var DISCORD_RPC_CHANNEL = "/dsh-discord";
|
|
36
|
+
var STATUS_ENDPOINT = "adapter.status";
|
|
37
|
+
|
|
38
|
+
// src/settings-namespace.ts
|
|
39
|
+
var DISCORD_SETTINGS_NAMESPACE = "dsh-discord";
|
|
40
|
+
|
|
41
|
+
// node_modules/.pnpm/immer@10.2.0/node_modules/immer/dist/immer.mjs
|
|
42
|
+
var NOTHING = Symbol.for("immer-nothing");
|
|
43
|
+
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
44
|
+
var DRAFT_STATE = Symbol.for("immer-state");
|
|
45
|
+
var errors = true ? [
|
|
46
|
+
// All error codes, starting by 0:
|
|
47
|
+
function(plugin) {
|
|
48
|
+
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
49
|
+
},
|
|
50
|
+
function(thing) {
|
|
51
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
52
|
+
},
|
|
53
|
+
"This object has been frozen and should not be mutated",
|
|
54
|
+
function(data) {
|
|
55
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
56
|
+
},
|
|
57
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
58
|
+
"Immer forbids circular references",
|
|
59
|
+
"The first or second argument to `produce` must be a function",
|
|
60
|
+
"The third argument to `produce` must be a function or undefined",
|
|
61
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
62
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
63
|
+
function(thing) {
|
|
64
|
+
return `'current' expects a draft, got: ${thing}`;
|
|
65
|
+
},
|
|
66
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
67
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
68
|
+
"Immer only supports deleting array indices",
|
|
69
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
70
|
+
function(thing) {
|
|
71
|
+
return `'original' expects a draft, got: ${thing}`;
|
|
72
|
+
}
|
|
73
|
+
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
74
|
+
// See Patches.ts for additional errors
|
|
75
|
+
] : [];
|
|
76
|
+
function die(error, ...args) {
|
|
77
|
+
if (true) {
|
|
78
|
+
const e = errors[error];
|
|
79
|
+
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
80
|
+
throw new Error(`[Immer] ${msg}`);
|
|
81
|
+
}
|
|
82
|
+
throw new Error(
|
|
83
|
+
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
87
|
+
function isDraft(value) {
|
|
88
|
+
return !!value && !!value[DRAFT_STATE];
|
|
89
|
+
}
|
|
90
|
+
function isDraftable(value) {
|
|
91
|
+
if (!value)
|
|
92
|
+
return false;
|
|
93
|
+
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
94
|
+
}
|
|
95
|
+
var objectCtorString = Object.prototype.constructor.toString();
|
|
96
|
+
var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
|
|
97
|
+
function isPlainObject(value) {
|
|
98
|
+
if (!value || typeof value !== "object")
|
|
99
|
+
return false;
|
|
100
|
+
const proto = Object.getPrototypeOf(value);
|
|
101
|
+
if (proto === null || proto === Object.prototype)
|
|
102
|
+
return true;
|
|
103
|
+
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
104
|
+
if (Ctor === Object)
|
|
105
|
+
return true;
|
|
106
|
+
if (typeof Ctor !== "function")
|
|
107
|
+
return false;
|
|
108
|
+
let ctorString = cachedCtorStrings.get(Ctor);
|
|
109
|
+
if (ctorString === void 0) {
|
|
110
|
+
ctorString = Function.toString.call(Ctor);
|
|
111
|
+
cachedCtorStrings.set(Ctor, ctorString);
|
|
112
|
+
}
|
|
113
|
+
return ctorString === objectCtorString;
|
|
114
|
+
}
|
|
115
|
+
function each(obj, iter, strict = true) {
|
|
116
|
+
if (getArchtype(obj) === 0) {
|
|
117
|
+
const keys = strict ? Reflect.ownKeys(obj) : Object.keys(obj);
|
|
118
|
+
keys.forEach((key) => {
|
|
119
|
+
iter(key, obj[key], obj);
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function getArchtype(thing) {
|
|
126
|
+
const state = thing[DRAFT_STATE];
|
|
127
|
+
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
128
|
+
}
|
|
129
|
+
function has(thing, prop) {
|
|
130
|
+
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
131
|
+
}
|
|
132
|
+
function set(thing, propOrOldValue, value) {
|
|
133
|
+
const t = getArchtype(thing);
|
|
134
|
+
if (t === 2)
|
|
135
|
+
thing.set(propOrOldValue, value);
|
|
136
|
+
else if (t === 3) {
|
|
137
|
+
thing.add(value);
|
|
138
|
+
} else
|
|
139
|
+
thing[propOrOldValue] = value;
|
|
140
|
+
}
|
|
141
|
+
function is(x, y) {
|
|
142
|
+
if (x === y) {
|
|
143
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
144
|
+
} else {
|
|
145
|
+
return x !== x && y !== y;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function isMap(target) {
|
|
149
|
+
return target instanceof Map;
|
|
150
|
+
}
|
|
151
|
+
function isSet(target) {
|
|
152
|
+
return target instanceof Set;
|
|
153
|
+
}
|
|
154
|
+
function latest(state) {
|
|
155
|
+
return state.copy_ || state.base_;
|
|
156
|
+
}
|
|
157
|
+
function shallowCopy(base, strict) {
|
|
158
|
+
if (isMap(base)) {
|
|
159
|
+
return new Map(base);
|
|
160
|
+
}
|
|
161
|
+
if (isSet(base)) {
|
|
162
|
+
return new Set(base);
|
|
163
|
+
}
|
|
164
|
+
if (Array.isArray(base))
|
|
165
|
+
return Array.prototype.slice.call(base);
|
|
166
|
+
const isPlain = isPlainObject(base);
|
|
167
|
+
if (strict === true || strict === "class_only" && !isPlain) {
|
|
168
|
+
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
169
|
+
delete descriptors[DRAFT_STATE];
|
|
170
|
+
let keys = Reflect.ownKeys(descriptors);
|
|
171
|
+
for (let i = 0; i < keys.length; i++) {
|
|
172
|
+
const key = keys[i];
|
|
173
|
+
const desc = descriptors[key];
|
|
174
|
+
if (desc.writable === false) {
|
|
175
|
+
desc.writable = true;
|
|
176
|
+
desc.configurable = true;
|
|
177
|
+
}
|
|
178
|
+
if (desc.get || desc.set)
|
|
179
|
+
descriptors[key] = {
|
|
180
|
+
configurable: true,
|
|
181
|
+
writable: true,
|
|
182
|
+
// could live with !!desc.set as well here...
|
|
183
|
+
enumerable: desc.enumerable,
|
|
184
|
+
value: base[key]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return Object.create(getPrototypeOf(base), descriptors);
|
|
188
|
+
} else {
|
|
189
|
+
const proto = getPrototypeOf(base);
|
|
190
|
+
if (proto !== null && isPlain) {
|
|
191
|
+
return { ...base };
|
|
192
|
+
}
|
|
193
|
+
const obj = Object.create(proto);
|
|
194
|
+
return Object.assign(obj, base);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function freeze(obj, deep = false) {
|
|
198
|
+
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
199
|
+
return obj;
|
|
200
|
+
if (getArchtype(obj) > 1) {
|
|
201
|
+
Object.defineProperties(obj, {
|
|
202
|
+
set: dontMutateMethodOverride,
|
|
203
|
+
add: dontMutateMethodOverride,
|
|
204
|
+
clear: dontMutateMethodOverride,
|
|
205
|
+
delete: dontMutateMethodOverride
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
Object.freeze(obj);
|
|
209
|
+
if (deep)
|
|
210
|
+
Object.values(obj).forEach((value) => freeze(value, true));
|
|
211
|
+
return obj;
|
|
212
|
+
}
|
|
213
|
+
function dontMutateFrozenCollections() {
|
|
214
|
+
die(2);
|
|
215
|
+
}
|
|
216
|
+
var dontMutateMethodOverride = {
|
|
217
|
+
value: dontMutateFrozenCollections
|
|
218
|
+
};
|
|
219
|
+
function isFrozen(obj) {
|
|
220
|
+
if (obj === null || typeof obj !== "object")
|
|
221
|
+
return true;
|
|
222
|
+
return Object.isFrozen(obj);
|
|
223
|
+
}
|
|
224
|
+
var plugins = {};
|
|
225
|
+
function getPlugin(pluginKey) {
|
|
226
|
+
const plugin = plugins[pluginKey];
|
|
227
|
+
if (!plugin) {
|
|
228
|
+
die(0, pluginKey);
|
|
229
|
+
}
|
|
230
|
+
return plugin;
|
|
231
|
+
}
|
|
232
|
+
var currentScope;
|
|
233
|
+
function getCurrentScope() {
|
|
234
|
+
return currentScope;
|
|
235
|
+
}
|
|
236
|
+
function createScope(parent_, immer_) {
|
|
237
|
+
return {
|
|
238
|
+
drafts_: [],
|
|
239
|
+
parent_,
|
|
240
|
+
immer_,
|
|
241
|
+
// Whenever the modified draft contains a draft from another scope, we
|
|
242
|
+
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
243
|
+
canAutoFreeze_: true,
|
|
244
|
+
unfinalizedDrafts_: 0
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function usePatchesInScope(scope, patchListener) {
|
|
248
|
+
if (patchListener) {
|
|
249
|
+
getPlugin("Patches");
|
|
250
|
+
scope.patches_ = [];
|
|
251
|
+
scope.inversePatches_ = [];
|
|
252
|
+
scope.patchListener_ = patchListener;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function revokeScope(scope) {
|
|
256
|
+
leaveScope(scope);
|
|
257
|
+
scope.drafts_.forEach(revokeDraft);
|
|
258
|
+
scope.drafts_ = null;
|
|
259
|
+
}
|
|
260
|
+
function leaveScope(scope) {
|
|
261
|
+
if (scope === currentScope) {
|
|
262
|
+
currentScope = scope.parent_;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function enterScope(immer2) {
|
|
266
|
+
return currentScope = createScope(currentScope, immer2);
|
|
267
|
+
}
|
|
268
|
+
function revokeDraft(draft) {
|
|
269
|
+
const state = draft[DRAFT_STATE];
|
|
270
|
+
if (state.type_ === 0 || state.type_ === 1)
|
|
271
|
+
state.revoke_();
|
|
272
|
+
else
|
|
273
|
+
state.revoked_ = true;
|
|
274
|
+
}
|
|
275
|
+
function processResult(result, scope) {
|
|
276
|
+
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
277
|
+
const baseDraft = scope.drafts_[0];
|
|
278
|
+
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
279
|
+
if (isReplaced) {
|
|
280
|
+
if (baseDraft[DRAFT_STATE].modified_) {
|
|
281
|
+
revokeScope(scope);
|
|
282
|
+
die(4);
|
|
283
|
+
}
|
|
284
|
+
if (isDraftable(result)) {
|
|
285
|
+
result = finalize(scope, result);
|
|
286
|
+
if (!scope.parent_)
|
|
287
|
+
maybeFreeze(scope, result);
|
|
288
|
+
}
|
|
289
|
+
if (scope.patches_) {
|
|
290
|
+
getPlugin("Patches").generateReplacementPatches_(
|
|
291
|
+
baseDraft[DRAFT_STATE].base_,
|
|
292
|
+
result,
|
|
293
|
+
scope.patches_,
|
|
294
|
+
scope.inversePatches_
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
result = finalize(scope, baseDraft, []);
|
|
299
|
+
}
|
|
300
|
+
revokeScope(scope);
|
|
301
|
+
if (scope.patches_) {
|
|
302
|
+
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
303
|
+
}
|
|
304
|
+
return result !== NOTHING ? result : void 0;
|
|
305
|
+
}
|
|
306
|
+
function finalize(rootScope, value, path) {
|
|
307
|
+
if (isFrozen(value))
|
|
308
|
+
return value;
|
|
309
|
+
const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
|
|
310
|
+
const state = value[DRAFT_STATE];
|
|
311
|
+
if (!state) {
|
|
312
|
+
each(
|
|
313
|
+
value,
|
|
314
|
+
(key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path),
|
|
315
|
+
useStrictIteration
|
|
316
|
+
);
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
if (state.scope_ !== rootScope)
|
|
320
|
+
return value;
|
|
321
|
+
if (!state.modified_) {
|
|
322
|
+
maybeFreeze(rootScope, state.base_, true);
|
|
323
|
+
return state.base_;
|
|
324
|
+
}
|
|
325
|
+
if (!state.finalized_) {
|
|
326
|
+
state.finalized_ = true;
|
|
327
|
+
state.scope_.unfinalizedDrafts_--;
|
|
328
|
+
const result = state.copy_;
|
|
329
|
+
let resultEach = result;
|
|
330
|
+
let isSet2 = false;
|
|
331
|
+
if (state.type_ === 3) {
|
|
332
|
+
resultEach = new Set(result);
|
|
333
|
+
result.clear();
|
|
334
|
+
isSet2 = true;
|
|
335
|
+
}
|
|
336
|
+
each(
|
|
337
|
+
resultEach,
|
|
338
|
+
(key, childValue) => finalizeProperty(
|
|
339
|
+
rootScope,
|
|
340
|
+
state,
|
|
341
|
+
result,
|
|
342
|
+
key,
|
|
343
|
+
childValue,
|
|
344
|
+
path,
|
|
345
|
+
isSet2
|
|
346
|
+
),
|
|
347
|
+
useStrictIteration
|
|
348
|
+
);
|
|
349
|
+
maybeFreeze(rootScope, result, false);
|
|
350
|
+
if (path && rootScope.patches_) {
|
|
351
|
+
getPlugin("Patches").generatePatches_(
|
|
352
|
+
state,
|
|
353
|
+
path,
|
|
354
|
+
rootScope.patches_,
|
|
355
|
+
rootScope.inversePatches_
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return state.copy_;
|
|
360
|
+
}
|
|
361
|
+
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
362
|
+
if (childValue == null) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (typeof childValue !== "object" && !targetIsSet) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const childIsFrozen = isFrozen(childValue);
|
|
369
|
+
if (childIsFrozen && !targetIsSet) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (childValue === targetObject)
|
|
373
|
+
die(5);
|
|
374
|
+
if (isDraft(childValue)) {
|
|
375
|
+
const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
|
|
376
|
+
!has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
|
|
377
|
+
const res = finalize(rootScope, childValue, path);
|
|
378
|
+
set(targetObject, prop, res);
|
|
379
|
+
if (isDraft(res)) {
|
|
380
|
+
rootScope.canAutoFreeze_ = false;
|
|
381
|
+
} else
|
|
382
|
+
return;
|
|
383
|
+
} else if (targetIsSet) {
|
|
384
|
+
targetObject.add(childValue);
|
|
385
|
+
}
|
|
386
|
+
if (isDraftable(childValue) && !childIsFrozen) {
|
|
387
|
+
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (parentState && parentState.base_ && parentState.base_[prop] === childValue && childIsFrozen) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
finalize(rootScope, childValue);
|
|
394
|
+
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && (isMap(targetObject) ? targetObject.has(prop) : Object.prototype.propertyIsEnumerable.call(targetObject, prop)))
|
|
395
|
+
maybeFreeze(rootScope, childValue);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function maybeFreeze(scope, value, deep = false) {
|
|
399
|
+
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
400
|
+
freeze(value, deep);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function createProxyProxy(base, parent) {
|
|
404
|
+
const isArray = Array.isArray(base);
|
|
405
|
+
const state = {
|
|
406
|
+
type_: isArray ? 1 : 0,
|
|
407
|
+
// Track which produce call this is associated with.
|
|
408
|
+
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
409
|
+
// True for both shallow and deep changes.
|
|
410
|
+
modified_: false,
|
|
411
|
+
// Used during finalization.
|
|
412
|
+
finalized_: false,
|
|
413
|
+
// Track which properties have been assigned (true) or deleted (false).
|
|
414
|
+
assigned_: {},
|
|
415
|
+
// The parent draft state.
|
|
416
|
+
parent_: parent,
|
|
417
|
+
// The base state.
|
|
418
|
+
base_: base,
|
|
419
|
+
// The base proxy.
|
|
420
|
+
draft_: null,
|
|
421
|
+
// set below
|
|
422
|
+
// The base copy with any updated values.
|
|
423
|
+
copy_: null,
|
|
424
|
+
// Called by the `produce` function.
|
|
425
|
+
revoke_: null,
|
|
426
|
+
isManual_: false
|
|
427
|
+
};
|
|
428
|
+
let target = state;
|
|
429
|
+
let traps = objectTraps;
|
|
430
|
+
if (isArray) {
|
|
431
|
+
target = [state];
|
|
432
|
+
traps = arrayTraps;
|
|
433
|
+
}
|
|
434
|
+
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
435
|
+
state.draft_ = proxy;
|
|
436
|
+
state.revoke_ = revoke;
|
|
437
|
+
return proxy;
|
|
438
|
+
}
|
|
439
|
+
var objectTraps = {
|
|
440
|
+
get(state, prop) {
|
|
441
|
+
if (prop === DRAFT_STATE)
|
|
442
|
+
return state;
|
|
443
|
+
const source = latest(state);
|
|
444
|
+
if (!has(source, prop)) {
|
|
445
|
+
return readPropFromProto(state, source, prop);
|
|
446
|
+
}
|
|
447
|
+
const value = source[prop];
|
|
448
|
+
if (state.finalized_ || !isDraftable(value)) {
|
|
449
|
+
return value;
|
|
450
|
+
}
|
|
451
|
+
if (value === peek(state.base_, prop)) {
|
|
452
|
+
prepareCopy(state);
|
|
453
|
+
return state.copy_[prop] = createProxy(value, state);
|
|
454
|
+
}
|
|
455
|
+
return value;
|
|
456
|
+
},
|
|
457
|
+
has(state, prop) {
|
|
458
|
+
return prop in latest(state);
|
|
459
|
+
},
|
|
460
|
+
ownKeys(state) {
|
|
461
|
+
return Reflect.ownKeys(latest(state));
|
|
462
|
+
},
|
|
463
|
+
set(state, prop, value) {
|
|
464
|
+
const desc = getDescriptorFromProto(latest(state), prop);
|
|
465
|
+
if (desc?.set) {
|
|
466
|
+
desc.set.call(state.draft_, value);
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
469
|
+
if (!state.modified_) {
|
|
470
|
+
const current2 = peek(latest(state), prop);
|
|
471
|
+
const currentState = current2?.[DRAFT_STATE];
|
|
472
|
+
if (currentState && currentState.base_ === value) {
|
|
473
|
+
state.copy_[prop] = value;
|
|
474
|
+
state.assigned_[prop] = false;
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
|
|
478
|
+
return true;
|
|
479
|
+
prepareCopy(state);
|
|
480
|
+
markChanged(state);
|
|
481
|
+
}
|
|
482
|
+
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
483
|
+
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
484
|
+
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
485
|
+
return true;
|
|
486
|
+
state.copy_[prop] = value;
|
|
487
|
+
state.assigned_[prop] = true;
|
|
488
|
+
return true;
|
|
489
|
+
},
|
|
490
|
+
deleteProperty(state, prop) {
|
|
491
|
+
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
492
|
+
state.assigned_[prop] = false;
|
|
493
|
+
prepareCopy(state);
|
|
494
|
+
markChanged(state);
|
|
495
|
+
} else {
|
|
496
|
+
delete state.assigned_[prop];
|
|
497
|
+
}
|
|
498
|
+
if (state.copy_) {
|
|
499
|
+
delete state.copy_[prop];
|
|
500
|
+
}
|
|
501
|
+
return true;
|
|
502
|
+
},
|
|
503
|
+
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
504
|
+
// the same guarantee in ES5 mode.
|
|
505
|
+
getOwnPropertyDescriptor(state, prop) {
|
|
506
|
+
const owner = latest(state);
|
|
507
|
+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
508
|
+
if (!desc)
|
|
509
|
+
return desc;
|
|
510
|
+
return {
|
|
511
|
+
writable: true,
|
|
512
|
+
configurable: state.type_ !== 1 || prop !== "length",
|
|
513
|
+
enumerable: desc.enumerable,
|
|
514
|
+
value: owner[prop]
|
|
515
|
+
};
|
|
516
|
+
},
|
|
517
|
+
defineProperty() {
|
|
518
|
+
die(11);
|
|
519
|
+
},
|
|
520
|
+
getPrototypeOf(state) {
|
|
521
|
+
return getPrototypeOf(state.base_);
|
|
522
|
+
},
|
|
523
|
+
setPrototypeOf() {
|
|
524
|
+
die(12);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
var arrayTraps = {};
|
|
528
|
+
each(objectTraps, (key, fn) => {
|
|
529
|
+
arrayTraps[key] = function() {
|
|
530
|
+
arguments[0] = arguments[0][0];
|
|
531
|
+
return fn.apply(this, arguments);
|
|
532
|
+
};
|
|
533
|
+
});
|
|
534
|
+
arrayTraps.deleteProperty = function(state, prop) {
|
|
535
|
+
if (isNaN(parseInt(prop)))
|
|
536
|
+
die(13);
|
|
537
|
+
return arrayTraps.set.call(this, state, prop, void 0);
|
|
538
|
+
};
|
|
539
|
+
arrayTraps.set = function(state, prop, value) {
|
|
540
|
+
if (prop !== "length" && isNaN(parseInt(prop)))
|
|
541
|
+
die(14);
|
|
542
|
+
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
543
|
+
};
|
|
544
|
+
function peek(draft, prop) {
|
|
545
|
+
const state = draft[DRAFT_STATE];
|
|
546
|
+
const source = state ? latest(state) : draft;
|
|
547
|
+
return source[prop];
|
|
548
|
+
}
|
|
549
|
+
function readPropFromProto(state, source, prop) {
|
|
550
|
+
const desc = getDescriptorFromProto(source, prop);
|
|
551
|
+
return desc ? `value` in desc ? desc.value : (
|
|
552
|
+
// This is a very special case, if the prop is a getter defined by the
|
|
553
|
+
// prototype, we should invoke it with the draft as context!
|
|
554
|
+
desc.get?.call(state.draft_)
|
|
555
|
+
) : void 0;
|
|
556
|
+
}
|
|
557
|
+
function getDescriptorFromProto(source, prop) {
|
|
558
|
+
if (!(prop in source))
|
|
559
|
+
return void 0;
|
|
560
|
+
let proto = getPrototypeOf(source);
|
|
561
|
+
while (proto) {
|
|
562
|
+
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
563
|
+
if (desc)
|
|
564
|
+
return desc;
|
|
565
|
+
proto = getPrototypeOf(proto);
|
|
566
|
+
}
|
|
567
|
+
return void 0;
|
|
568
|
+
}
|
|
569
|
+
function markChanged(state) {
|
|
570
|
+
if (!state.modified_) {
|
|
571
|
+
state.modified_ = true;
|
|
572
|
+
if (state.parent_) {
|
|
573
|
+
markChanged(state.parent_);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function prepareCopy(state) {
|
|
578
|
+
if (!state.copy_) {
|
|
579
|
+
state.copy_ = shallowCopy(
|
|
580
|
+
state.base_,
|
|
581
|
+
state.scope_.immer_.useStrictShallowCopy_
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
var Immer2 = class {
|
|
586
|
+
constructor(config) {
|
|
587
|
+
this.autoFreeze_ = true;
|
|
588
|
+
this.useStrictShallowCopy_ = false;
|
|
589
|
+
this.useStrictIteration_ = true;
|
|
590
|
+
this.produce = (base, recipe, patchListener) => {
|
|
591
|
+
if (typeof base === "function" && typeof recipe !== "function") {
|
|
592
|
+
const defaultBase = recipe;
|
|
593
|
+
recipe = base;
|
|
594
|
+
const self = this;
|
|
595
|
+
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
596
|
+
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
if (typeof recipe !== "function")
|
|
600
|
+
die(6);
|
|
601
|
+
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
602
|
+
die(7);
|
|
603
|
+
let result;
|
|
604
|
+
if (isDraftable(base)) {
|
|
605
|
+
const scope = enterScope(this);
|
|
606
|
+
const proxy = createProxy(base, void 0);
|
|
607
|
+
let hasError = true;
|
|
608
|
+
try {
|
|
609
|
+
result = recipe(proxy);
|
|
610
|
+
hasError = false;
|
|
611
|
+
} finally {
|
|
612
|
+
if (hasError)
|
|
613
|
+
revokeScope(scope);
|
|
614
|
+
else
|
|
615
|
+
leaveScope(scope);
|
|
616
|
+
}
|
|
617
|
+
usePatchesInScope(scope, patchListener);
|
|
618
|
+
return processResult(result, scope);
|
|
619
|
+
} else if (!base || typeof base !== "object") {
|
|
620
|
+
result = recipe(base);
|
|
621
|
+
if (result === void 0)
|
|
622
|
+
result = base;
|
|
623
|
+
if (result === NOTHING)
|
|
624
|
+
result = void 0;
|
|
625
|
+
if (this.autoFreeze_)
|
|
626
|
+
freeze(result, true);
|
|
627
|
+
if (patchListener) {
|
|
628
|
+
const p = [];
|
|
629
|
+
const ip = [];
|
|
630
|
+
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
631
|
+
patchListener(p, ip);
|
|
632
|
+
}
|
|
633
|
+
return result;
|
|
634
|
+
} else
|
|
635
|
+
die(1, base);
|
|
636
|
+
};
|
|
637
|
+
this.produceWithPatches = (base, recipe) => {
|
|
638
|
+
if (typeof base === "function") {
|
|
639
|
+
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
640
|
+
}
|
|
641
|
+
let patches, inversePatches;
|
|
642
|
+
const result = this.produce(base, recipe, (p, ip) => {
|
|
643
|
+
patches = p;
|
|
644
|
+
inversePatches = ip;
|
|
645
|
+
});
|
|
646
|
+
return [result, patches, inversePatches];
|
|
647
|
+
};
|
|
648
|
+
if (typeof config?.autoFreeze === "boolean")
|
|
649
|
+
this.setAutoFreeze(config.autoFreeze);
|
|
650
|
+
if (typeof config?.useStrictShallowCopy === "boolean")
|
|
651
|
+
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
652
|
+
if (typeof config?.useStrictIteration === "boolean")
|
|
653
|
+
this.setUseStrictIteration(config.useStrictIteration);
|
|
654
|
+
}
|
|
655
|
+
createDraft(base) {
|
|
656
|
+
if (!isDraftable(base))
|
|
657
|
+
die(8);
|
|
658
|
+
if (isDraft(base))
|
|
659
|
+
base = current(base);
|
|
660
|
+
const scope = enterScope(this);
|
|
661
|
+
const proxy = createProxy(base, void 0);
|
|
662
|
+
proxy[DRAFT_STATE].isManual_ = true;
|
|
663
|
+
leaveScope(scope);
|
|
664
|
+
return proxy;
|
|
665
|
+
}
|
|
666
|
+
finishDraft(draft, patchListener) {
|
|
667
|
+
const state = draft && draft[DRAFT_STATE];
|
|
668
|
+
if (!state || !state.isManual_)
|
|
669
|
+
die(9);
|
|
670
|
+
const { scope_: scope } = state;
|
|
671
|
+
usePatchesInScope(scope, patchListener);
|
|
672
|
+
return processResult(void 0, scope);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
676
|
+
*
|
|
677
|
+
* By default, auto-freezing is enabled.
|
|
678
|
+
*/
|
|
679
|
+
setAutoFreeze(value) {
|
|
680
|
+
this.autoFreeze_ = value;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Pass true to enable strict shallow copy.
|
|
684
|
+
*
|
|
685
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
686
|
+
*/
|
|
687
|
+
setUseStrictShallowCopy(value) {
|
|
688
|
+
this.useStrictShallowCopy_ = value;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Pass false to use faster iteration that skips non-enumerable properties
|
|
692
|
+
* but still handles symbols for compatibility.
|
|
693
|
+
*
|
|
694
|
+
* By default, strict iteration is enabled (includes all own properties).
|
|
695
|
+
*/
|
|
696
|
+
setUseStrictIteration(value) {
|
|
697
|
+
this.useStrictIteration_ = value;
|
|
698
|
+
}
|
|
699
|
+
shouldUseStrictIteration() {
|
|
700
|
+
return this.useStrictIteration_;
|
|
701
|
+
}
|
|
702
|
+
applyPatches(base, patches) {
|
|
703
|
+
let i;
|
|
704
|
+
for (i = patches.length - 1; i >= 0; i--) {
|
|
705
|
+
const patch = patches[i];
|
|
706
|
+
if (patch.path.length === 0 && patch.op === "replace") {
|
|
707
|
+
base = patch.value;
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (i > -1) {
|
|
712
|
+
patches = patches.slice(i + 1);
|
|
713
|
+
}
|
|
714
|
+
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
715
|
+
if (isDraft(base)) {
|
|
716
|
+
return applyPatchesImpl(base, patches);
|
|
717
|
+
}
|
|
718
|
+
return this.produce(
|
|
719
|
+
base,
|
|
720
|
+
(draft) => applyPatchesImpl(draft, patches)
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
function createProxy(value, parent) {
|
|
725
|
+
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
726
|
+
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
727
|
+
scope.drafts_.push(draft);
|
|
728
|
+
return draft;
|
|
729
|
+
}
|
|
730
|
+
function current(value) {
|
|
731
|
+
if (!isDraft(value))
|
|
732
|
+
die(10, value);
|
|
733
|
+
return currentImpl(value);
|
|
734
|
+
}
|
|
735
|
+
function currentImpl(value) {
|
|
736
|
+
if (!isDraftable(value) || isFrozen(value))
|
|
737
|
+
return value;
|
|
738
|
+
const state = value[DRAFT_STATE];
|
|
739
|
+
let copy;
|
|
740
|
+
let strict = true;
|
|
741
|
+
if (state) {
|
|
742
|
+
if (!state.modified_)
|
|
743
|
+
return state.base_;
|
|
744
|
+
state.finalized_ = true;
|
|
745
|
+
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
746
|
+
strict = state.scope_.immer_.shouldUseStrictIteration();
|
|
747
|
+
} else {
|
|
748
|
+
copy = shallowCopy(value, true);
|
|
749
|
+
}
|
|
750
|
+
each(
|
|
751
|
+
copy,
|
|
752
|
+
(key, childValue) => {
|
|
753
|
+
set(copy, key, currentImpl(childValue));
|
|
754
|
+
},
|
|
755
|
+
strict
|
|
756
|
+
);
|
|
757
|
+
if (state) {
|
|
758
|
+
state.finalized_ = false;
|
|
759
|
+
}
|
|
760
|
+
return copy;
|
|
761
|
+
}
|
|
762
|
+
var immer = new Immer2();
|
|
763
|
+
var produce = immer.produce;
|
|
764
|
+
|
|
765
|
+
// src/client/snapshot-store.ts
|
|
766
|
+
function createLocalSnapshotStore(initial) {
|
|
767
|
+
let current2 = initial;
|
|
768
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
769
|
+
const notify = () => {
|
|
770
|
+
for (const listener of [...listeners]) listener();
|
|
771
|
+
};
|
|
772
|
+
return {
|
|
773
|
+
getSnapshot: () => current2,
|
|
774
|
+
subscribe(listener) {
|
|
775
|
+
listeners.add(listener);
|
|
776
|
+
return () => {
|
|
777
|
+
listeners.delete(listener);
|
|
778
|
+
};
|
|
779
|
+
},
|
|
780
|
+
update(mutator) {
|
|
781
|
+
const next = produce(current2, mutator);
|
|
782
|
+
if (next !== current2) {
|
|
783
|
+
current2 = next;
|
|
784
|
+
notify();
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
set(next) {
|
|
788
|
+
current2 = next;
|
|
789
|
+
notify();
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/client/settings-model.ts
|
|
795
|
+
var CONNECTION_KEYS = {
|
|
796
|
+
connected: "discordStatusConnected",
|
|
797
|
+
connecting: "discordStatusConnecting",
|
|
798
|
+
disconnected: "discordStatusDisconnected",
|
|
799
|
+
"invalid-token": "discordStatusInvalidToken",
|
|
800
|
+
"intents-blocked": "discordStatusIntentsBlocked",
|
|
801
|
+
"permissions-blocked": "discordStatusPermissionsBlocked"
|
|
802
|
+
};
|
|
803
|
+
var HINT_KEYS = {
|
|
804
|
+
"configure-token": "discordHintConfigureToken",
|
|
805
|
+
"token-rejected": "discordHintTokenRejected",
|
|
806
|
+
"enable-intents": "discordHintEnableIntents",
|
|
807
|
+
"gateway-closed": "discordHintGatewayClosed",
|
|
808
|
+
"channel-permissions": "discordHintChannelPermissions"
|
|
809
|
+
};
|
|
810
|
+
function presentAdapterStatus(view) {
|
|
811
|
+
return {
|
|
812
|
+
connectionKey: CONNECTION_KEYS[view.connection],
|
|
813
|
+
...view.hint === void 0 ? {} : { hintKey: HINT_KEYS[view.hint] },
|
|
814
|
+
actionable: view.hint !== void 0,
|
|
815
|
+
tokenConfigured: view.token !== "unconfigured"
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// src/client/card-form.ts
|
|
820
|
+
var DISCORD_ID_FIELDS = [
|
|
821
|
+
"allowedGuildIds",
|
|
822
|
+
"memberUserIds",
|
|
823
|
+
"memberRoleIds",
|
|
824
|
+
"administratorUserIds",
|
|
825
|
+
"administratorRoleIds",
|
|
826
|
+
"deniedUserIds",
|
|
827
|
+
"deniedRoleIds",
|
|
828
|
+
"hostOperatorUserIds"
|
|
829
|
+
];
|
|
830
|
+
var ARCHIVE_FIELD = "threadAutoArchiveMinutes";
|
|
831
|
+
var LANGUAGE_FIELD = "language";
|
|
832
|
+
function parseLanguage(text) {
|
|
833
|
+
return text === "auto" || text === "zh" || text === "en" ? text : void 0;
|
|
834
|
+
}
|
|
835
|
+
function isIdField(field) {
|
|
836
|
+
return DISCORD_ID_FIELDS.includes(field);
|
|
837
|
+
}
|
|
838
|
+
function isLanguageField(field) {
|
|
839
|
+
return field === LANGUAGE_FIELD;
|
|
840
|
+
}
|
|
841
|
+
var LANGUAGE_CHOICES = [
|
|
842
|
+
{ value: "zh", label: "\u4E2D\u6587" },
|
|
843
|
+
{ value: "en", label: "English" }
|
|
844
|
+
];
|
|
845
|
+
var ARCHIVE_CHOICES = [
|
|
846
|
+
{ value: "60", label: "1 \u5C0F\u65F6" },
|
|
847
|
+
{ value: "1440", label: "1 \u5929" },
|
|
848
|
+
{ value: "4320", label: "3 \u5929" },
|
|
849
|
+
{ value: "10080", label: "7 \u5929" }
|
|
850
|
+
];
|
|
851
|
+
function parseArchiveMinutes(text) {
|
|
852
|
+
const parsed = Number.parseInt(text, 10);
|
|
853
|
+
return ARCHIVE_CHOICES.some((choice) => choice.value === String(parsed)) ? parsed : void 0;
|
|
854
|
+
}
|
|
855
|
+
var DISCORD_SNOWFLAKE = /^\d{17,20}$/u;
|
|
856
|
+
function parseIdList(text) {
|
|
857
|
+
const items = text.split(/\r?\n/u).map((item) => item.trim()).filter(Boolean);
|
|
858
|
+
const unique = [...new Set(items)];
|
|
859
|
+
return unique.every((item) => DISCORD_SNOWFLAKE.test(item)) ? unique : void 0;
|
|
860
|
+
}
|
|
861
|
+
var DiscordCardForm = class {
|
|
862
|
+
constructor(scope) {
|
|
863
|
+
this.scope = scope;
|
|
864
|
+
this.scope.subscribe(() => {
|
|
865
|
+
this.publish();
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
staged = /* @__PURE__ */ new Map();
|
|
869
|
+
listeners = /* @__PURE__ */ new Set();
|
|
870
|
+
saving = false;
|
|
871
|
+
failed = false;
|
|
872
|
+
status = void 0;
|
|
873
|
+
/**
|
|
874
|
+
* Publish the Host's sanitized status view. Edits, saves, and failures
|
|
875
|
+
* never touch it — connection state is the Host's report, not form state.
|
|
876
|
+
*/
|
|
877
|
+
setStatus(view) {
|
|
878
|
+
this.status = view === void 0 ? void 0 : presentAdapterStatus(view);
|
|
879
|
+
this.publish();
|
|
880
|
+
}
|
|
881
|
+
/** Publish the card state the renderer reads through its bound selector. */
|
|
882
|
+
bind() {
|
|
883
|
+
const store = createLocalSnapshotStore(this.project());
|
|
884
|
+
this.listeners.add(() => {
|
|
885
|
+
store.set(this.project());
|
|
886
|
+
});
|
|
887
|
+
return store;
|
|
888
|
+
}
|
|
889
|
+
/** Build the edit, reset, save, and discard actions bound to this form. */
|
|
890
|
+
actions() {
|
|
891
|
+
return {
|
|
892
|
+
edit: (field, text) => {
|
|
893
|
+
this.staged.set(field, { text, clear: false });
|
|
894
|
+
this.failed = false;
|
|
895
|
+
this.publish();
|
|
896
|
+
},
|
|
897
|
+
resetField: (field) => {
|
|
898
|
+
this.staged.set(field, { text: "", clear: true });
|
|
899
|
+
this.failed = false;
|
|
900
|
+
this.publish();
|
|
901
|
+
},
|
|
902
|
+
save: () => {
|
|
903
|
+
void this.save();
|
|
904
|
+
},
|
|
905
|
+
discard: () => {
|
|
906
|
+
if (this.staged.size === 0 && !this.failed) return;
|
|
907
|
+
this.staged.clear();
|
|
908
|
+
this.failed = false;
|
|
909
|
+
this.publish();
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
project() {
|
|
914
|
+
const snapshot = this.scope.getSnapshot();
|
|
915
|
+
const plan = this.plan();
|
|
916
|
+
const fields = {};
|
|
917
|
+
for (const field of DISCORD_ID_FIELDS) {
|
|
918
|
+
fields[field] = this.fieldState(field);
|
|
919
|
+
}
|
|
920
|
+
fields[ARCHIVE_FIELD] = this.fieldState(ARCHIVE_FIELD);
|
|
921
|
+
fields[LANGUAGE_FIELD] = this.fieldState(LANGUAGE_FIELD);
|
|
922
|
+
return {
|
|
923
|
+
...fields,
|
|
924
|
+
available: snapshot.status === "ready",
|
|
925
|
+
writable: snapshot.writable,
|
|
926
|
+
dirty: plan.length > 0,
|
|
927
|
+
invalid: plan.some((item) => item.write === void 0),
|
|
928
|
+
saving: this.saving,
|
|
929
|
+
failed: this.failed,
|
|
930
|
+
status: this.status
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
fieldState(field) {
|
|
934
|
+
const staged = this.staged.get(field);
|
|
935
|
+
if (staged === void 0) {
|
|
936
|
+
return {
|
|
937
|
+
text: this.currentText(field),
|
|
938
|
+
overridden: this.stored(field),
|
|
939
|
+
invalid: false
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
const parsed = isIdField(field) ? parseIdList(staged.text) : isLanguageField(field) ? parseLanguage(staged.text) : parseArchiveMinutes(staged.text);
|
|
943
|
+
return {
|
|
944
|
+
text: staged.text,
|
|
945
|
+
overridden: parsed !== void 0,
|
|
946
|
+
invalid: parsed === void 0
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
currentText(field) {
|
|
950
|
+
const section = this.snapshot().value;
|
|
951
|
+
const value = section?.[field];
|
|
952
|
+
if (Array.isArray(value)) return value.join("\n");
|
|
953
|
+
if (typeof value === "string") return value;
|
|
954
|
+
if (typeof value === "number") return String(value);
|
|
955
|
+
return "";
|
|
956
|
+
}
|
|
957
|
+
snapshot() {
|
|
958
|
+
return this.scope.getSnapshot();
|
|
959
|
+
}
|
|
960
|
+
userLayer() {
|
|
961
|
+
return this.snapshot().user;
|
|
962
|
+
}
|
|
963
|
+
stored(field) {
|
|
964
|
+
const user = this.userLayer();
|
|
965
|
+
return user !== void 0 && Object.hasOwn(user, field);
|
|
966
|
+
}
|
|
967
|
+
plan() {
|
|
968
|
+
const plan = [];
|
|
969
|
+
for (const [field, staged] of this.staged) {
|
|
970
|
+
if (staged.clear) {
|
|
971
|
+
if (this.stored(field)) plan.push({ field, write: () => this.clear(field) });
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if (isIdField(field)) {
|
|
975
|
+
const parsed2 = parseIdList(staged.text);
|
|
976
|
+
if (parsed2 === void 0) plan.push({ field, write: void 0 });
|
|
977
|
+
else plan.push({ field, write: () => this.store(field, parsed2) });
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (isLanguageField(field)) {
|
|
981
|
+
const language = parseLanguage(staged.text);
|
|
982
|
+
if (language === void 0) plan.push({ field, write: void 0 });
|
|
983
|
+
else plan.push({ field, write: () => this.store(field, language) });
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
const parsed = parseArchiveMinutes(staged.text);
|
|
987
|
+
if (parsed === void 0) plan.push({ field, write: void 0 });
|
|
988
|
+
else plan.push({ field, write: () => this.store(field, parsed) });
|
|
989
|
+
}
|
|
990
|
+
return plan;
|
|
991
|
+
}
|
|
992
|
+
async clear(field) {
|
|
993
|
+
await this.scope.unset(field);
|
|
994
|
+
return !this.stored(field);
|
|
995
|
+
}
|
|
996
|
+
async store(field, value) {
|
|
997
|
+
await this.scope.set(field, value);
|
|
998
|
+
return this.userLayer()?.[field] !== void 0;
|
|
999
|
+
}
|
|
1000
|
+
async save() {
|
|
1001
|
+
const plan = this.plan();
|
|
1002
|
+
const writes = plan.flatMap((item) => item.write === void 0 ? [] : [item.write]);
|
|
1003
|
+
if (plan.length === 0 || this.saving || writes.length !== plan.length) return;
|
|
1004
|
+
this.saving = true;
|
|
1005
|
+
this.failed = false;
|
|
1006
|
+
this.publish();
|
|
1007
|
+
let landed = true;
|
|
1008
|
+
for (const write of writes) {
|
|
1009
|
+
landed = await write().catch(() => false) && landed;
|
|
1010
|
+
}
|
|
1011
|
+
if (landed) this.staged.clear();
|
|
1012
|
+
this.saving = false;
|
|
1013
|
+
this.failed = !landed;
|
|
1014
|
+
this.publish();
|
|
1015
|
+
}
|
|
1016
|
+
publish() {
|
|
1017
|
+
for (const listener of this.listeners) listener();
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
// src/client/card-controller.ts
|
|
1022
|
+
var DiscordCardController = class {
|
|
1023
|
+
form;
|
|
1024
|
+
management;
|
|
1025
|
+
constructor(scope) {
|
|
1026
|
+
this.form = new DiscordCardForm(scope);
|
|
1027
|
+
}
|
|
1028
|
+
/** Attach the token write/connect path once the RPC face is known. */
|
|
1029
|
+
setManagement(management) {
|
|
1030
|
+
this.management = management;
|
|
1031
|
+
}
|
|
1032
|
+
/** Publish the Host's sanitized connection status onto the card. */
|
|
1033
|
+
setStatus(view) {
|
|
1034
|
+
this.form.setStatus(view);
|
|
1035
|
+
}
|
|
1036
|
+
/** Build the face the registration's inject factory returns per entry. */
|
|
1037
|
+
face() {
|
|
1038
|
+
return {
|
|
1039
|
+
...this.form.actions(),
|
|
1040
|
+
hooks: {
|
|
1041
|
+
discordCard: this.form.bind()
|
|
1042
|
+
},
|
|
1043
|
+
...this.management === void 0 ? {} : { management: this.management }
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
// src/client/nav-icon.tsx
|
|
1049
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1050
|
+
var MARK_PATH = "M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z";
|
|
1051
|
+
function DiscordMark({ size = 16 }) {
|
|
1052
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { viewBox: "0 0 24 24", width: size, height: size, fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: MARK_PATH }) });
|
|
1053
|
+
}
|
|
1054
|
+
function markElement(size) {
|
|
1055
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
1056
|
+
const svg = document.createElementNS(ns, "svg");
|
|
1057
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
1058
|
+
svg.setAttribute("width", String(size));
|
|
1059
|
+
svg.setAttribute("height", String(size));
|
|
1060
|
+
svg.setAttribute("fill", "currentColor");
|
|
1061
|
+
svg.setAttribute("aria-hidden", "true");
|
|
1062
|
+
svg.setAttribute("data-discord-mark", "true");
|
|
1063
|
+
const path = document.createElementNS(ns, "path");
|
|
1064
|
+
path.setAttribute("d", MARK_PATH);
|
|
1065
|
+
svg.appendChild(path);
|
|
1066
|
+
return svg;
|
|
1067
|
+
}
|
|
1068
|
+
function sweepNavIcons() {
|
|
1069
|
+
const cells = document.querySelectorAll("button");
|
|
1070
|
+
cells.forEach((cell) => {
|
|
1071
|
+
const label = cell.querySelector('[class*="navLabel"]');
|
|
1072
|
+
if (label === null || label.textContent !== "Discord") return;
|
|
1073
|
+
const svg = cell.querySelector("svg");
|
|
1074
|
+
if (svg === null || svg.getAttribute("data-discord-mark") === "true") return;
|
|
1075
|
+
const replacement = markElement(16);
|
|
1076
|
+
const hostClass = svg.getAttribute("class");
|
|
1077
|
+
if (hostClass !== null) replacement.setAttribute("class", hostClass);
|
|
1078
|
+
svg.replaceWith(replacement);
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
function installDiscordNavIcon() {
|
|
1082
|
+
if (typeof document === "undefined" || typeof MutationObserver === "undefined") {
|
|
1083
|
+
return () => {
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
let scheduled = false;
|
|
1087
|
+
const sweepScheduled = () => {
|
|
1088
|
+
if (scheduled) return;
|
|
1089
|
+
scheduled = true;
|
|
1090
|
+
requestAnimationFrame(() => {
|
|
1091
|
+
scheduled = false;
|
|
1092
|
+
sweepNavIcons();
|
|
1093
|
+
});
|
|
1094
|
+
};
|
|
1095
|
+
const observer = new MutationObserver(sweepScheduled);
|
|
1096
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
1097
|
+
sweepNavIcons();
|
|
1098
|
+
return () => {
|
|
1099
|
+
observer.disconnect();
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// src/client/DiscordSettingsCard.tsx
|
|
1104
|
+
var import_react2 = require("react");
|
|
1105
|
+
|
|
1106
|
+
// src/client/fields.tsx
|
|
1107
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1108
|
+
function SelectField(props) {
|
|
1109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-dsh-discord-field": "", children: [
|
|
1110
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-dsh-discord-field-head": "", children: [
|
|
1111
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: props.id, children: props.label }),
|
|
1112
|
+
props.overridden ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-dsh-discord-badges": "", children: [
|
|
1113
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-dsh-discord-badge": "overridden", children: props.overriddenLabel }),
|
|
1114
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1115
|
+
"button",
|
|
1116
|
+
{
|
|
1117
|
+
type: "button",
|
|
1118
|
+
disabled: props.disabled,
|
|
1119
|
+
onClick: props.onReset,
|
|
1120
|
+
children: props.resetLabel
|
|
1121
|
+
}
|
|
1122
|
+
)
|
|
1123
|
+
] }) : null
|
|
1124
|
+
] }),
|
|
1125
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1126
|
+
"select",
|
|
1127
|
+
{
|
|
1128
|
+
id: props.id,
|
|
1129
|
+
"aria-invalid": props.invalid,
|
|
1130
|
+
value: props.text,
|
|
1131
|
+
disabled: props.disabled,
|
|
1132
|
+
onChange: (event) => {
|
|
1133
|
+
props.onEdit(event.currentTarget.value);
|
|
1134
|
+
},
|
|
1135
|
+
children: props.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: option.value, children: option.label }, option.value))
|
|
1136
|
+
}
|
|
1137
|
+
),
|
|
1138
|
+
(props.invalid || props.hint !== "") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { "data-dsh-discord-field-note": props.invalid ? "invalid" : "hint", children: props.invalid ? props.invalidLabel : props.hint })
|
|
1139
|
+
] });
|
|
1140
|
+
}
|
|
1141
|
+
function ValueField(props) {
|
|
1142
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-dsh-discord-field": "", children: [
|
|
1143
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-dsh-discord-field-head": "", children: [
|
|
1144
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: props.id, children: props.label }),
|
|
1145
|
+
props.overridden ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-dsh-discord-badges": "", children: [
|
|
1146
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-dsh-discord-badge": "overridden", children: props.overriddenLabel }),
|
|
1147
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1148
|
+
"button",
|
|
1149
|
+
{
|
|
1150
|
+
type: "button",
|
|
1151
|
+
disabled: props.disabled,
|
|
1152
|
+
onClick: props.onReset,
|
|
1153
|
+
children: props.resetLabel
|
|
1154
|
+
}
|
|
1155
|
+
)
|
|
1156
|
+
] }) : null
|
|
1157
|
+
] }),
|
|
1158
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1159
|
+
"textarea",
|
|
1160
|
+
{
|
|
1161
|
+
id: props.id,
|
|
1162
|
+
rows: 3,
|
|
1163
|
+
"aria-invalid": props.invalid,
|
|
1164
|
+
value: props.text,
|
|
1165
|
+
disabled: props.disabled,
|
|
1166
|
+
onInput: (event) => {
|
|
1167
|
+
props.onEdit(event.currentTarget.value);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
),
|
|
1171
|
+
(props.invalid || props.hint !== "") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { "data-dsh-discord-field-note": props.invalid ? "invalid" : "hint", children: props.invalid ? props.invalidLabel : props.hint })
|
|
1172
|
+
] });
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// src/client/PluginCard.tsx
|
|
1176
|
+
var import_react = require("react");
|
|
1177
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1178
|
+
function PluginCard(props) {
|
|
1179
|
+
const [open, setOpen] = (0, import_react.useState)(true);
|
|
1180
|
+
const { state } = props;
|
|
1181
|
+
if (!state.available) return null;
|
|
1182
|
+
const blocked = !state.dirty || state.invalid || state.saving;
|
|
1183
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-dsh-discord-card": open ? "open" : "closed", children: [
|
|
1184
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1185
|
+
"button",
|
|
1186
|
+
{
|
|
1187
|
+
type: "button",
|
|
1188
|
+
"aria-expanded": open,
|
|
1189
|
+
"aria-label": `${props.copy[open ? "collapse" : "expand"]}: ${props.title}`,
|
|
1190
|
+
onClick: () => {
|
|
1191
|
+
setOpen(!open);
|
|
1192
|
+
},
|
|
1193
|
+
children: [
|
|
1194
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { "data-dsh-discord-card-head": "", children: [
|
|
1195
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { "data-dsh-discord-card-title": "", children: [
|
|
1196
|
+
props.icon,
|
|
1197
|
+
props.title
|
|
1198
|
+
] }),
|
|
1199
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-dsh-discord-card-description": "", children: props.description })
|
|
1200
|
+
] }),
|
|
1201
|
+
state.dirty ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-dsh-discord-badge": "unsaved", children: props.copy.unsaved }) : null
|
|
1202
|
+
]
|
|
1203
|
+
}
|
|
1204
|
+
),
|
|
1205
|
+
open ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-dsh-discord-card-body": "", children: [
|
|
1206
|
+
!state.writable ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { role: "status", children: props.copy.readOnly }) : null,
|
|
1207
|
+
props.children,
|
|
1208
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-dsh-discord-card-footer": "", children: [
|
|
1209
|
+
state.failed ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { role: "status", children: props.copy.saveFailed }) : null,
|
|
1210
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1211
|
+
"button",
|
|
1212
|
+
{
|
|
1213
|
+
type: "button",
|
|
1214
|
+
disabled: !state.dirty || state.saving,
|
|
1215
|
+
onClick: props.onDiscard,
|
|
1216
|
+
children: props.copy.discard
|
|
1217
|
+
}
|
|
1218
|
+
),
|
|
1219
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1220
|
+
"button",
|
|
1221
|
+
{
|
|
1222
|
+
type: "button",
|
|
1223
|
+
disabled: blocked,
|
|
1224
|
+
onClick: props.onSave,
|
|
1225
|
+
children: props.copy[state.saving ? "saving" : "save"]
|
|
1226
|
+
}
|
|
1227
|
+
)
|
|
1228
|
+
] })
|
|
1229
|
+
] }) : null
|
|
1230
|
+
] });
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
// src/client/DiscordSettingsCard.tsx
|
|
1234
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1235
|
+
var STATUS_DOT_COLOR = {
|
|
1236
|
+
discordStatusConnected: "#23a55a",
|
|
1237
|
+
discordStatusConnecting: "#f0b232",
|
|
1238
|
+
discordStatusDisconnected: "#f23f43",
|
|
1239
|
+
discordStatusInvalidToken: "#f23f43",
|
|
1240
|
+
discordStatusIntentsBlocked: "#f23f43",
|
|
1241
|
+
discordStatusPermissionsBlocked: "#f23f43"
|
|
1242
|
+
};
|
|
1243
|
+
var CARD_CSS = `
|
|
1244
|
+
[data-dsh-discord-card] { display: flex; flex-direction: column; gap: 24px; padding: 4px 2px 0; }
|
|
1245
|
+
[data-dsh-discord-card-head] { display: flex; flex-direction: column; gap: 2px; text-align: left; }
|
|
1246
|
+
[data-dsh-discord-card-title] { font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
|
|
1247
|
+
[data-dsh-discord-card-title] svg { opacity: .85; }
|
|
1248
|
+
[data-dsh-discord-card-description] { font-size: 12px; opacity: .55; }
|
|
1249
|
+
button[aria-expanded] { all: unset; cursor: pointer; display: block; width: 100%; box-sizing: border-box; }
|
|
1250
|
+
button[aria-expanded]:focus-visible { outline: 2px solid rgba(88, 101, 242, .8); border-radius: 8px; }
|
|
1251
|
+
[data-dsh-discord-badge] { display: inline-block; font-size: 11px; line-height: 18px; padding: 0 8px; border-radius: 999px; }
|
|
1252
|
+
[data-dsh-discord-badge="unsaved"] { background: rgba(250, 204, 21, .16); color: #facc15; }
|
|
1253
|
+
[data-dsh-discord-status] { display: flex; align-items: center; gap: 8px; font-size: 13px; }
|
|
1254
|
+
[data-dsh-discord-status-dot] { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 6px currentColor; }
|
|
1255
|
+
[data-dsh-discord-field] { display: flex; flex-direction: column; gap: 6px; }
|
|
1256
|
+
[data-dsh-discord-field-help] + [data-dsh-discord-field], [data-dsh-discord-token] { margin-top: 8px; }
|
|
1257
|
+
[data-dsh-discord-field-head] { display: flex; align-items: center; gap: 8px; }
|
|
1258
|
+
[data-dsh-discord-field-head] label { font-size: 13px; font-weight: 500; }
|
|
1259
|
+
[data-dsh-discord-badges] { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
|
|
1260
|
+
[data-dsh-discord-badge="overridden"] { background: rgba(250, 204, 21, .16); color: #facc15; }
|
|
1261
|
+
[data-dsh-discord-field-head] button { all: unset; cursor: pointer; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: rgba(127, 127, 127, .18); }
|
|
1262
|
+
[data-dsh-discord-field-head] button:hover { background: rgba(127, 127, 127, .3); }
|
|
1263
|
+
[data-dsh-discord-field] textarea, [data-dsh-discord-field] select {
|
|
1264
|
+
width: 100%; box-sizing: border-box; color: inherit; font: inherit; font-size: 13px;
|
|
1265
|
+
background: rgba(127, 127, 127, .12); border: 1px solid rgba(127, 127, 127, .28);
|
|
1266
|
+
border-radius: 8px; padding: 8px 10px; resize: vertical;
|
|
1267
|
+
}
|
|
1268
|
+
[data-dsh-discord-field] textarea:focus-visible, [data-dsh-discord-field] select:focus-visible {
|
|
1269
|
+
outline: none; border-color: rgba(88, 101, 242, .9);
|
|
1270
|
+
}
|
|
1271
|
+
[data-dsh-discord-field] textarea[aria-invalid="true"], [data-dsh-discord-field] select[aria-invalid="true"] {
|
|
1272
|
+
border-color: rgba(242, 63, 67, .8);
|
|
1273
|
+
}
|
|
1274
|
+
[data-dsh-discord-field-note] { margin: 0; font-size: 12px; opacity: .55; }
|
|
1275
|
+
[data-dsh-discord-field-note="invalid"] { opacity: 1; color: #f23f43; }
|
|
1276
|
+
[data-dsh-discord-field-help] { margin: -2px 0 0; font-size: 12px; opacity: .55; line-height: 1.6; }
|
|
1277
|
+
[data-dsh-discord-disconnect] { all: unset; cursor: pointer; margin-left: auto; font-size: 12px; padding: 2px 10px; border-radius: 6px; background: rgba(127, 127, 127, .18); }
|
|
1278
|
+
[data-dsh-discord-disconnect]:hover { background: rgba(242, 63, 67, .18); color: #f23f43; }
|
|
1279
|
+
[data-dsh-discord-token] { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid rgba(127, 127, 127, .28); border-radius: 10px; }
|
|
1280
|
+
[data-dsh-discord-token-row] { display: flex; gap: 10px; }
|
|
1281
|
+
[data-dsh-discord-token-row] input {
|
|
1282
|
+
flex: 1; min-width: 0; box-sizing: border-box; color: inherit; font: inherit; font-size: 13px;
|
|
1283
|
+
background: rgba(127, 127, 127, .12); border: 1px solid rgba(127, 127, 127, .28); border-radius: 8px; padding: 8px 10px;
|
|
1284
|
+
}
|
|
1285
|
+
[data-dsh-discord-token-row] input:focus-visible { outline: none; border-color: rgba(88, 101, 242, .9); }
|
|
1286
|
+
[data-dsh-discord-token-row] button { all: unset; cursor: pointer; font-size: 13px; padding: 7px 16px; border-radius: 8px; background: rgba(88, 101, 242, .9); color: #fff; white-space: nowrap; }
|
|
1287
|
+
[data-dsh-discord-token-row] button:disabled { opacity: .45; cursor: default; }
|
|
1288
|
+
[data-dsh-discord-token-error] { margin: 0; font-size: 12px; color: #f23f43; }
|
|
1289
|
+
[data-dsh-discord-card-footer] { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
|
|
1290
|
+
[data-dsh-discord-card-footer] button { all: unset; cursor: pointer; font-size: 13px; padding: 6px 16px; border-radius: 8px; }
|
|
1291
|
+
[data-dsh-discord-card-footer] button[type="button"]:first-child { background: rgba(127, 127, 127, .18); }
|
|
1292
|
+
[data-dsh-discord-card-footer] button:not(:disabled) { background: rgba(88, 101, 242, .9); color: #fff; }
|
|
1293
|
+
[data-dsh-discord-card-footer] button[type="button"]:first-child:not(:disabled) { background: rgba(127, 127, 127, .18); color: inherit; }
|
|
1294
|
+
[data-dsh-discord-card-footer] button:disabled { opacity: .4; cursor: default; }
|
|
1295
|
+
[data-dsh-discord-card-footer] button:not(:disabled):hover { filter: brightness(1.12); }
|
|
1296
|
+
`;
|
|
1297
|
+
function TokenSetup(props) {
|
|
1298
|
+
const { t } = props;
|
|
1299
|
+
const [token, setToken] = (0, import_react2.useState)("");
|
|
1300
|
+
const [connecting, setConnecting] = (0, import_react2.useState)(false);
|
|
1301
|
+
const [error, setError] = (0, import_react2.useState)("");
|
|
1302
|
+
const connectionKey = props.connectionKey;
|
|
1303
|
+
const visible = connectionKey === void 0 || connectionKey === "discordStatusDisconnected" || connectionKey === "discordStatusInvalidToken" || connectionKey === "discordStatusIntentsBlocked" || connectionKey === "discordStatusPermissionsBlocked";
|
|
1304
|
+
if (!visible) return null;
|
|
1305
|
+
const submit = () => {
|
|
1306
|
+
if (props.management === void 0 || connecting) return;
|
|
1307
|
+
const value = token.trim();
|
|
1308
|
+
setConnecting(true);
|
|
1309
|
+
setError("");
|
|
1310
|
+
const write = value === "" ? Promise.resolve() : props.management.setToken(value).then(() => {
|
|
1311
|
+
setToken("");
|
|
1312
|
+
});
|
|
1313
|
+
write.then(() => {
|
|
1314
|
+
props.management?.connect();
|
|
1315
|
+
props.management?.refresh();
|
|
1316
|
+
setConnecting(false);
|
|
1317
|
+
}, (cause) => {
|
|
1318
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1319
|
+
setConnecting(false);
|
|
1320
|
+
});
|
|
1321
|
+
};
|
|
1322
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-dsh-discord-token": "", children: [
|
|
1323
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-dsh-discord-field-head": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: "plugin-config-discord-token", children: t("discordTokenLabel") }) }),
|
|
1324
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-dsh-discord-token-row": "", children: [
|
|
1325
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1326
|
+
"input",
|
|
1327
|
+
{
|
|
1328
|
+
id: "plugin-config-discord-token",
|
|
1329
|
+
type: "password",
|
|
1330
|
+
autoComplete: "off",
|
|
1331
|
+
placeholder: props.tokenConfigured ? t("discordTokenSaved") : t("discordTokenPlaceholder"),
|
|
1332
|
+
value: token,
|
|
1333
|
+
disabled: connecting,
|
|
1334
|
+
onChange: (event) => {
|
|
1335
|
+
setToken(event.currentTarget.value);
|
|
1336
|
+
},
|
|
1337
|
+
onKeyDown: (event) => {
|
|
1338
|
+
if (event.key === "Enter") submit();
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
),
|
|
1342
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", disabled: connecting || !props.tokenConfigured && token.trim() === "", onClick: submit, children: connecting ? t("discordTokenConnecting") : t("discordTokenConnect") })
|
|
1343
|
+
] }),
|
|
1344
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { "data-dsh-discord-field-help": "", children: props.tokenConfigured ? t("discordTokenReconnectHint") : t("discordTokenHelp") }),
|
|
1345
|
+
error !== "" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { "data-dsh-discord-token-error": "", children: error })
|
|
1346
|
+
] });
|
|
1347
|
+
}
|
|
1348
|
+
function DiscordSettingsCard(props) {
|
|
1349
|
+
const { t } = props;
|
|
1350
|
+
const state = props.useDiscordCard((snapshot) => snapshot);
|
|
1351
|
+
if (!state.available) return null;
|
|
1352
|
+
const copy = {
|
|
1353
|
+
expand: t("expand"),
|
|
1354
|
+
collapse: t("collapse"),
|
|
1355
|
+
unsaved: t("unsaved"),
|
|
1356
|
+
readOnly: t("readOnly"),
|
|
1357
|
+
saveFailed: t("saveFailed"),
|
|
1358
|
+
discard: t("discard"),
|
|
1359
|
+
save: t("save"),
|
|
1360
|
+
saving: t("saving")
|
|
1361
|
+
};
|
|
1362
|
+
const disabled = !state.writable;
|
|
1363
|
+
const languageChoices = [
|
|
1364
|
+
{ value: "auto", label: t("discordLanguageAuto") },
|
|
1365
|
+
...LANGUAGE_CHOICES
|
|
1366
|
+
];
|
|
1367
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1368
|
+
PluginCard,
|
|
1369
|
+
{
|
|
1370
|
+
copy,
|
|
1371
|
+
icon: DiscordMark({}),
|
|
1372
|
+
title: t("discordTitle"),
|
|
1373
|
+
description: t("discordDescription"),
|
|
1374
|
+
state,
|
|
1375
|
+
onSave: props.save,
|
|
1376
|
+
onDiscard: props.discard,
|
|
1377
|
+
children: [
|
|
1378
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: CARD_CSS }),
|
|
1379
|
+
state.status !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { "data-dsh-discord-status": "", children: [
|
|
1380
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1381
|
+
"span",
|
|
1382
|
+
{
|
|
1383
|
+
"data-dsh-discord-status-dot": "",
|
|
1384
|
+
style: { background: STATUS_DOT_COLOR[state.status.connectionKey] ?? "#f23f43", color: STATUS_DOT_COLOR[state.status.connectionKey] ?? "#f23f43" }
|
|
1385
|
+
}
|
|
1386
|
+
),
|
|
1387
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1388
|
+
t(state.status.connectionKey),
|
|
1389
|
+
state.status.hintKey !== void 0 ? ` \u2014 ${t(state.status.hintKey)}` : ""
|
|
1390
|
+
] }),
|
|
1391
|
+
(state.status.connectionKey === "discordStatusConnected" || state.status.connectionKey === "discordStatusConnecting") && props.management !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1392
|
+
"button",
|
|
1393
|
+
{
|
|
1394
|
+
type: "button",
|
|
1395
|
+
"data-dsh-discord-disconnect": "",
|
|
1396
|
+
onClick: () => {
|
|
1397
|
+
props.management?.disconnect();
|
|
1398
|
+
props.management?.refresh();
|
|
1399
|
+
},
|
|
1400
|
+
children: t("discordDisconnect")
|
|
1401
|
+
}
|
|
1402
|
+
)
|
|
1403
|
+
] }),
|
|
1404
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TokenSetup, { management: props.management, connectionKey: state.status?.connectionKey, hintKey: state.status?.hintKey, tokenConfigured: state.status?.tokenConfigured ?? false, t }),
|
|
1405
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1406
|
+
ValueField,
|
|
1407
|
+
{
|
|
1408
|
+
id: "plugin-config-discord-allowedGuildIds",
|
|
1409
|
+
label: t("discordAllowedGuildIds"),
|
|
1410
|
+
hint: "",
|
|
1411
|
+
overriddenLabel: t("overridden"),
|
|
1412
|
+
resetLabel: t("reset"),
|
|
1413
|
+
invalidLabel: t("discordInvalidIds"),
|
|
1414
|
+
disabled,
|
|
1415
|
+
...state.allowedGuildIds,
|
|
1416
|
+
onEdit: (text) => {
|
|
1417
|
+
props.edit("allowedGuildIds", text);
|
|
1418
|
+
},
|
|
1419
|
+
onReset: () => {
|
|
1420
|
+
props.resetField("allowedGuildIds");
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
),
|
|
1424
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { "data-dsh-discord-field-help": "", children: t("discordGuildIdHelp") }),
|
|
1425
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1426
|
+
SelectField,
|
|
1427
|
+
{
|
|
1428
|
+
id: `plugin-config-discord-${ARCHIVE_FIELD}`,
|
|
1429
|
+
label: t("discordThreadAutoArchive"),
|
|
1430
|
+
hint: t("discordThreadAutoArchiveHint"),
|
|
1431
|
+
overriddenLabel: t("overridden"),
|
|
1432
|
+
resetLabel: t("reset"),
|
|
1433
|
+
invalidLabel: t("discordInvalidArchive"),
|
|
1434
|
+
disabled,
|
|
1435
|
+
options: ARCHIVE_CHOICES,
|
|
1436
|
+
...state[ARCHIVE_FIELD],
|
|
1437
|
+
onEdit: (text) => {
|
|
1438
|
+
props.edit(ARCHIVE_FIELD, text);
|
|
1439
|
+
},
|
|
1440
|
+
onReset: () => {
|
|
1441
|
+
props.resetField(ARCHIVE_FIELD);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
),
|
|
1445
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1446
|
+
SelectField,
|
|
1447
|
+
{
|
|
1448
|
+
id: `plugin-config-discord-${LANGUAGE_FIELD}`,
|
|
1449
|
+
label: t("discordLanguage"),
|
|
1450
|
+
hint: t("discordLanguageHint"),
|
|
1451
|
+
overriddenLabel: t("overridden"),
|
|
1452
|
+
resetLabel: t("reset"),
|
|
1453
|
+
invalidLabel: t("discordInvalidLanguage"),
|
|
1454
|
+
disabled,
|
|
1455
|
+
options: languageChoices,
|
|
1456
|
+
...state[LANGUAGE_FIELD],
|
|
1457
|
+
onEdit: (text) => {
|
|
1458
|
+
props.edit(LANGUAGE_FIELD, text);
|
|
1459
|
+
},
|
|
1460
|
+
onReset: () => {
|
|
1461
|
+
props.resetField(LANGUAGE_FIELD);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
)
|
|
1465
|
+
]
|
|
1466
|
+
}
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// src/client/index.ts
|
|
1471
|
+
var name = "dsh-discord-client";
|
|
1472
|
+
var inject = ["settingsScope", "slots", "connection", "locale"];
|
|
1473
|
+
var STATUS_POLL_MS = 3e4;
|
|
1474
|
+
function isStatusView(value) {
|
|
1475
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1476
|
+
const candidate = value;
|
|
1477
|
+
return typeof candidate["token"] === "string" && typeof candidate["connection"] === "string";
|
|
1478
|
+
}
|
|
1479
|
+
function apply(ctx) {
|
|
1480
|
+
const scope = ctx.settingsScope.bind({ namespace: DISCORD_SETTINGS_NAMESPACE });
|
|
1481
|
+
const controller = new DiscordCardController(scope);
|
|
1482
|
+
ctx.locale.register("dsh-discord", {
|
|
1483
|
+
en: DISCORD_CARD_LOCALE_EN,
|
|
1484
|
+
zh: DISCORD_CARD_LOCALE_ZH
|
|
1485
|
+
});
|
|
1486
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
1487
|
+
name: "settings.section",
|
|
1488
|
+
id: "discord",
|
|
1489
|
+
order: 100,
|
|
1490
|
+
label: "Discord",
|
|
1491
|
+
locale: "dsh-discord",
|
|
1492
|
+
registrant: name,
|
|
1493
|
+
inject: () => controller.face()
|
|
1494
|
+
}, DiscordSettingsCard));
|
|
1495
|
+
ctx.effect(() => installDiscordNavIcon(), "discord nav icon shim");
|
|
1496
|
+
const call = ctx.connection?.rpc?.call;
|
|
1497
|
+
if (typeof call !== "function") return;
|
|
1498
|
+
controller.setManagement({
|
|
1499
|
+
setToken: (value) => Promise.resolve(call(DISCORD_RPC_CHANNEL, "credentials.set", { value }, void 0)).then((answer) => {
|
|
1500
|
+
if (typeof answer === "object" && answer !== null && "ok" in answer && answer.ok) return;
|
|
1501
|
+
const message = typeof answer === "object" && answer !== null && "error" in answer ? answer.error?.message ?? "The Host rejected the token." : "The Host rejected the token.";
|
|
1502
|
+
throw new TypeError(message);
|
|
1503
|
+
}),
|
|
1504
|
+
connect: () => {
|
|
1505
|
+
void call(DISCORD_RPC_CHANNEL, "adapter.connect", {}, void 0);
|
|
1506
|
+
},
|
|
1507
|
+
disconnect: () => {
|
|
1508
|
+
void call(DISCORD_RPC_CHANNEL, "adapter.disconnect", {}, void 0);
|
|
1509
|
+
},
|
|
1510
|
+
// Immediate feedback for connect/disconnect clicks: the handshake takes
|
|
1511
|
+
// a moment, so poll twice — once for the offline/starting state and once
|
|
1512
|
+
// after the gateway should have landed on READY or a terminal close.
|
|
1513
|
+
refresh: () => {
|
|
1514
|
+
setTimeout(poll, 600);
|
|
1515
|
+
setTimeout(poll, 2500);
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
const poll = () => {
|
|
1519
|
+
void call(DISCORD_RPC_CHANNEL, STATUS_ENDPOINT, {}, void 0).then((answer) => {
|
|
1520
|
+
if (typeof answer !== "object" || answer === null || !("ok" in answer)) return;
|
|
1521
|
+
const envelope = answer;
|
|
1522
|
+
controller.setStatus(envelope.ok && isStatusView(envelope.value) ? envelope.value : void 0);
|
|
1523
|
+
}).catch(() => {
|
|
1524
|
+
controller.setStatus(void 0);
|
|
1525
|
+
});
|
|
1526
|
+
};
|
|
1527
|
+
poll();
|
|
1528
|
+
const timer = setInterval(poll, STATUS_POLL_MS);
|
|
1529
|
+
ctx.effect(() => () => {
|
|
1530
|
+
clearInterval(timer);
|
|
1531
|
+
}, "discord status poll");
|
|
1532
|
+
}
|
|
1533
|
+
var DISCORD_CARD_LOCALE_EN = {
|
|
1534
|
+
discordTitle: "Discord",
|
|
1535
|
+
discordDescription: "Bind channels to Workspaces and authorize who may use the bot.",
|
|
1536
|
+
discordAllowedGuildIds: "Allowed servers",
|
|
1537
|
+
discordGuildIdHelp: 'How to get it: enable Developer Mode in Discord (User Settings \u2192 Advanced), then right-click the target server and choose "Copy Server ID". One ID per line.',
|
|
1538
|
+
discordTokenLabel: "Bot Token",
|
|
1539
|
+
discordTokenPlaceholder: "Paste the bot token",
|
|
1540
|
+
discordTokenConnect: "Connect",
|
|
1541
|
+
discordTokenConnecting: "Connecting\u2026",
|
|
1542
|
+
discordTokenHelp: "From the Discord Developer Portal \u2192 your application \u2192 Bot \u2192 Reset Token. Stored in the Host credential service; never written to settings or logs.",
|
|
1543
|
+
discordDisconnect: "Disconnect",
|
|
1544
|
+
discordTokenSaved: "Saved token \u2014 leave empty to reconnect",
|
|
1545
|
+
discordTokenReconnectHint: "The token is stored in the Host credential service. Leave empty to reconnect, or paste a new one to replace it.",
|
|
1546
|
+
discordThreadAutoArchive: "Task Thread Auto-archive",
|
|
1547
|
+
discordThreadAutoArchiveHint: "Idle task threads archive automatically",
|
|
1548
|
+
discordLanguage: "Bot Language",
|
|
1549
|
+
discordLanguageHint: "Language of bot-visible messages",
|
|
1550
|
+
discordLanguageAuto: "Follow DSH language",
|
|
1551
|
+
discordInvalidLanguage: "Unsupported language",
|
|
1552
|
+
discordInvalidIds: "IDs must be 17\u201320 digit snowflakes, one per line",
|
|
1553
|
+
discordInvalidArchive: "Unsupported archive duration",
|
|
1554
|
+
discordStatusConnected: "Connected",
|
|
1555
|
+
discordStatusConnecting: "Connecting\u2026",
|
|
1556
|
+
discordStatusDisconnected: "Disconnected",
|
|
1557
|
+
discordStatusInvalidToken: "Token rejected",
|
|
1558
|
+
discordStatusIntentsBlocked: "Gateway intents blocked",
|
|
1559
|
+
discordStatusPermissionsBlocked: "Missing channel permissions",
|
|
1560
|
+
discordHintConfigureToken: "Configure the bot token in credentials",
|
|
1561
|
+
discordHintTokenRejected: "Discord rejected the token \u2014 update it",
|
|
1562
|
+
discordHintEnableIntents: "Enable privileged intents in the Developer Portal",
|
|
1563
|
+
discordHintGatewayClosed: "Gateway closed unexpectedly",
|
|
1564
|
+
discordHintChannelPermissions: "The bot lacks permissions in this channel",
|
|
1565
|
+
reset: "Reset",
|
|
1566
|
+
expand: "Expand",
|
|
1567
|
+
collapse: "Collapse",
|
|
1568
|
+
unsaved: "Unsaved changes",
|
|
1569
|
+
readOnly: "Read-only",
|
|
1570
|
+
saveFailed: "Save failed",
|
|
1571
|
+
discard: "Discard",
|
|
1572
|
+
save: "Save",
|
|
1573
|
+
saving: "Saving\u2026",
|
|
1574
|
+
overridden: "Overridden"
|
|
1575
|
+
};
|
|
1576
|
+
var DISCORD_CARD_LOCALE_ZH = {
|
|
1577
|
+
discordTitle: "Discord",
|
|
1578
|
+
discordDescription: "\u5C06\u9891\u9053\u7ED1\u5B9A\u5230\u5DE5\u4F5C\u533A\uFF0C\u5E76\u6388\u6743\u53EF\u4F7F\u7528\u673A\u5668\u4EBA\u7684\u6210\u5458\u3002",
|
|
1579
|
+
discordAllowedGuildIds: "\u5141\u8BB8\u7684\u670D\u52A1\u5668",
|
|
1580
|
+
discordGuildIdHelp: "\u83B7\u53D6\u65B9\u5F0F\uFF1A\u5728 Discord \u4E2D\u5F00\u542F\u5F00\u53D1\u8005\u6A21\u5F0F\uFF08\u7528\u6237\u8BBE\u7F6E \u2192 \u9AD8\u7EA7\u8BBE\u7F6E\uFF09\uFF0C\u7136\u540E\u53F3\u952E\u70B9\u51FB\u76EE\u6807\u670D\u52A1\u5668 \u2192\u300C\u590D\u5236\u670D\u52A1\u5668 ID\u300D\u3002\u6BCF\u884C\u586B\u4E00\u4E2A ID\u3002",
|
|
1581
|
+
discordTokenLabel: "Bot Token",
|
|
1582
|
+
discordTokenPlaceholder: "\u7C98\u8D34 Bot Token",
|
|
1583
|
+
discordTokenConnect: "\u8FDE\u63A5",
|
|
1584
|
+
discordTokenConnecting: "\u8FDE\u63A5\u4E2D\u2026",
|
|
1585
|
+
discordTokenHelp: "\u6765\u81EA Discord \u5F00\u53D1\u8005\u95E8\u6237 \u2192 \u4F60\u7684\u5E94\u7528 \u2192 Bot \u2192 Reset Token\u3002\u7531 Host \u51ED\u636E\u670D\u52A1\u52A0\u5BC6\u4FDD\u5B58\uFF0C\u4E0D\u4F1A\u5199\u5165\u8BBE\u7F6E\u6216\u65E5\u5FD7\u3002",
|
|
1586
|
+
discordDisconnect: "\u65AD\u5F00\u8FDE\u63A5",
|
|
1587
|
+
discordTokenSaved: "\u5DF2\u4FDD\u5B58\u7684 Token \u2014 \u7559\u7A7A\u76F4\u63A5\u91CD\u65B0\u8FDE\u63A5",
|
|
1588
|
+
discordTokenReconnectHint: "Token \u5DF2\u4FDD\u5B58\u5728 Host \u51ED\u636E\u670D\u52A1\u4E2D\u3002\u7559\u7A7A\u76F4\u63A5\u91CD\u8FDE\uFF0C\u6216\u7C98\u8D34\u65B0 Token \u8FDB\u884C\u66FF\u6362\u3002",
|
|
1589
|
+
discordThreadAutoArchive: "\u4EFB\u52A1\u7EBF\u7A0B\u81EA\u52A8\u5F52\u6863",
|
|
1590
|
+
discordThreadAutoArchiveHint: "\u95F2\u7F6E\u7684\u4EFB\u52A1\u7EBF\u7A0B\u5230\u671F\u540E\u81EA\u52A8\u5F52\u6863",
|
|
1591
|
+
discordLanguage: "Bot \u8BED\u8A00",
|
|
1592
|
+
discordLanguageHint: "\u673A\u5668\u4EBA\u53EF\u89C1\u6D88\u606F\u4F7F\u7528\u7684\u8BED\u8A00",
|
|
1593
|
+
discordLanguageAuto: "\u8DDF\u968F DSH \u8BED\u8A00",
|
|
1594
|
+
discordInvalidLanguage: "\u4E0D\u652F\u6301\u7684\u8BED\u8A00",
|
|
1595
|
+
discordInvalidIds: "ID \u5FC5\u987B\u662F 17\u201320 \u4F4D\u96EA\u82B1\u6570\u5B57\uFF0C\u6BCF\u884C\u4E00\u4E2A",
|
|
1596
|
+
discordInvalidArchive: "\u4E0D\u652F\u6301\u7684\u5F52\u6863\u65F6\u957F",
|
|
1597
|
+
discordStatusConnected: "\u5DF2\u8FDE\u63A5",
|
|
1598
|
+
discordStatusConnecting: "\u8FDE\u63A5\u4E2D\u2026",
|
|
1599
|
+
discordStatusDisconnected: "\u672A\u8FDE\u63A5",
|
|
1600
|
+
discordStatusInvalidToken: "Token \u88AB\u62D2\u7EDD",
|
|
1601
|
+
discordStatusIntentsBlocked: "Gateway intents \u88AB\u62D2",
|
|
1602
|
+
discordStatusPermissionsBlocked: "\u7F3A\u5C11\u9891\u9053\u6743\u9650",
|
|
1603
|
+
discordHintConfigureToken: "\u8BF7\u5728\u51ED\u636E\u4E2D\u914D\u7F6E Bot Token",
|
|
1604
|
+
discordHintTokenRejected: "Discord \u62D2\u7EDD\u4E86\u8BE5 Token\uFF0C\u8BF7\u66F4\u65B0",
|
|
1605
|
+
discordHintEnableIntents: "\u8BF7\u5728\u5F00\u53D1\u8005\u95E8\u6237\u5F00\u542F\u7279\u6743 intents",
|
|
1606
|
+
discordHintGatewayClosed: "Gateway \u8FDE\u63A5\u5F02\u5E38\u5173\u95ED",
|
|
1607
|
+
discordHintChannelPermissions: "Bot \u5728\u8BE5\u9891\u9053\u7F3A\u5C11\u6743\u9650",
|
|
1608
|
+
reset: "\u91CD\u7F6E",
|
|
1609
|
+
expand: "\u5C55\u5F00",
|
|
1610
|
+
collapse: "\u6536\u8D77",
|
|
1611
|
+
unsaved: "\u6709\u672A\u4FDD\u5B58\u4FEE\u6539",
|
|
1612
|
+
readOnly: "\u53EA\u8BFB",
|
|
1613
|
+
saveFailed: "\u4FDD\u5B58\u5931\u8D25",
|
|
1614
|
+
discard: "\u653E\u5F03",
|
|
1615
|
+
save: "\u4FDD\u5B58",
|
|
1616
|
+
saving: "\u4FDD\u5B58\u4E2D\u2026",
|
|
1617
|
+
overridden: "\u5DF2\u8986\u76D6"
|
|
1618
|
+
};
|
|
1619
|
+
|
|
1620
|
+
return module.exports;
|
|
1621
|
+
}
|
|
1622
|
+
});
|