@logictan/dsh-imagegen 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -2416,31 +2416,39 @@ window.__ModuleLoader__.load({
2416
2416
  invalid: write === void 0 && !(spec.secret === true && staged.text.trim() === "")
2417
2417
  };
2418
2418
  }
2419
- /** The actions the card's slot registration injects. */
2419
+ /**
2420
+ * The actions the card's slot registration injects.
2421
+ *
2422
+ * Built once. The slot calls `inject()` on every render, and a fresh object
2423
+ * with fresh closures each time changes the props the renderer subscribed
2424
+ * with, which re-renders forever (React error #185). These closures only ever
2425
+ * capture `this`, so one instance serves every call.
2426
+ */
2427
+ actionSet = {
2428
+ edit: (field, text) => {
2429
+ this.stage(field, {
2430
+ text,
2431
+ clear: false
2432
+ });
2433
+ },
2434
+ resetField: (field) => {
2435
+ this.stage(field, {
2436
+ text: this.specOf(field).format(this.baseValue(field)),
2437
+ clear: true
2438
+ });
2439
+ },
2440
+ save: () => {
2441
+ this.save();
2442
+ },
2443
+ discard: () => {
2444
+ if (this.staged.size === 0 && !this.failed) return;
2445
+ this.staged.clear();
2446
+ this.failed = false;
2447
+ this.publish();
2448
+ }
2449
+ };
2420
2450
  actions() {
2421
- return {
2422
- edit: (field, text) => {
2423
- this.stage(field, {
2424
- text,
2425
- clear: false
2426
- });
2427
- },
2428
- resetField: (field) => {
2429
- this.stage(field, {
2430
- text: this.specOf(field).format(this.baseValue(field)),
2431
- clear: true
2432
- });
2433
- },
2434
- save: () => {
2435
- this.save();
2436
- },
2437
- discard: () => {
2438
- if (this.staged.size === 0 && !this.failed) return;
2439
- this.staged.clear();
2440
- this.failed = false;
2441
- this.publish();
2442
- }
2443
- };
2451
+ return this.actionSet;
2444
2452
  }
2445
2453
  /**
2446
2454
  * Write every staged edit, then re-seed from what the Host accepted.
@@ -2671,36 +2679,44 @@ window.__ModuleLoader__.load({
2671
2679
  failed: this.failed
2672
2680
  };
2673
2681
  }
2674
- /** The actions the card's slot registration injects. */
2682
+ /**
2683
+ * The actions the card's slot registration injects, built once.
2684
+ *
2685
+ * The slot calls `inject()` on every render, and a fresh object with fresh
2686
+ * closures each time changes the props the renderer subscribed with, which
2687
+ * re-renders forever (React error #185). These closures only ever capture
2688
+ * `this`, so one instance serves every call.
2689
+ */
2690
+ actionSet = {
2691
+ setChannels: (channels) => {
2692
+ this.stageChannels(channels);
2693
+ },
2694
+ setChannelKey: (id, value) => {
2695
+ this.stageKey(id, value);
2696
+ },
2697
+ setDefaultChannel: (id) => {
2698
+ this.stagedDefault = id;
2699
+ this.failed = false;
2700
+ this.publish();
2701
+ },
2702
+ setDefaultModel: (model) => {
2703
+ this.stagedDefaultModel = model;
2704
+ this.failed = false;
2705
+ this.publish();
2706
+ },
2707
+ commit: () => this.commit(),
2708
+ discard: () => {
2709
+ if (this.stagedChannels === null && this.stagedKeys.size === 0 && this.stagedDefault === null && this.stagedDefaultModel === null && !this.failed) return;
2710
+ this.stagedChannels = null;
2711
+ this.stagedKeys.clear();
2712
+ this.stagedDefault = null;
2713
+ this.stagedDefaultModel = null;
2714
+ this.failed = false;
2715
+ this.publish();
2716
+ }
2717
+ };
2675
2718
  actions() {
2676
- return {
2677
- setChannels: (channels) => {
2678
- this.stageChannels(channels);
2679
- },
2680
- setChannelKey: (id, value) => {
2681
- this.stageKey(id, value);
2682
- },
2683
- setDefaultChannel: (id) => {
2684
- this.stagedDefault = id;
2685
- this.failed = false;
2686
- this.publish();
2687
- },
2688
- setDefaultModel: (model) => {
2689
- this.stagedDefaultModel = model;
2690
- this.failed = false;
2691
- this.publish();
2692
- },
2693
- commit: () => this.commit(),
2694
- discard: () => {
2695
- if (this.stagedChannels === null && this.stagedKeys.size === 0 && this.stagedDefault === null && this.stagedDefaultModel === null && !this.failed) return;
2696
- this.stagedChannels = null;
2697
- this.stagedKeys.clear();
2698
- this.stagedDefault = null;
2699
- this.stagedDefaultModel = null;
2700
- this.failed = false;
2701
- this.publish();
2702
- }
2703
- };
2719
+ return this.actionSet;
2704
2720
  }
2705
2721
  stageChannels(channels) {
2706
2722
  const cleaned = channels.map(stripChannel);
@@ -2991,73 +3007,73 @@ window.__ModuleLoader__.load({
2991
3007
  document.head.appendChild(tag);
2992
3008
  }
2993
3009
  var settings_card_module_css_default = {
2994
- "modelRowInputs": "_5JdLea_modelRowInputs",
2995
- "modelRowBadges": "_5JdLea_modelRowBadges",
2996
- "readOnly": "_5JdLea_readOnly",
2997
- "editorClose": "_5JdLea_editorClose",
2998
- "editorField": "_5JdLea_editorField",
2999
- "optionalContent": "_5JdLea_optionalContent",
3000
- "head": "_5JdLea_head",
3001
- "presetRow": "_5JdLea_presetRow",
3002
- "manualModelRow": "_5JdLea_manualModelRow",
3003
- "chevron": "_5JdLea_chevron",
3004
- "editorSectionHeader": "_5JdLea_editorSectionHeader",
3005
3010
  "badges": "_5JdLea_badges",
3011
+ "failed": "_5JdLea_failed",
3012
+ "deleteConfirmText": "_5JdLea_deleteConfirmText",
3013
+ "channelRow": "_5JdLea_channelRow",
3014
+ "presetInlineHeader": "_5JdLea_presetInlineHeader",
3015
+ "editorTools": "_5JdLea_editorTools",
3016
+ "chevron": "_5JdLea_chevron",
3017
+ "modelRowRemove": "_5JdLea_modelRowRemove",
3018
+ "inlineDisclosure": "_5JdLea_inlineDisclosure",
3019
+ "editorBackdrop": "_5JdLea_editorBackdrop",
3020
+ "sectionHint": "_5JdLea_sectionHint",
3021
+ "editorPanel": "_5JdLea_editorPanel",
3022
+ "channelMeta": "_5JdLea_channelMeta",
3006
3023
  "chevronOpen": "_5JdLea_chevronOpen",
3024
+ "headText": "_5JdLea_headText",
3025
+ "footer": "_5JdLea_footer",
3026
+ "editorField": "_5JdLea_editorField",
3027
+ "modelRow": "_5JdLea_modelRow",
3028
+ "disclosure": "_5JdLea_disclosure",
3029
+ "presetMeta": "_5JdLea_presetMeta",
3007
3030
  "editorDivider": "_5JdLea_editorDivider",
3008
- "editorFooter": "_5JdLea_editorFooter",
3031
+ "presetInline": "_5JdLea_presetInline",
3032
+ "name": "_5JdLea_name",
3033
+ "invalid": "_5JdLea_invalid",
3034
+ "reset": "_5JdLea_reset",
3035
+ "presetName": "_5JdLea_presetName",
3036
+ "card": "_5JdLea_card",
3037
+ "description": "_5JdLea_description",
3038
+ "channelEmpty": "_5JdLea_channelEmpty",
3039
+ "channelList": "_5JdLea_channelList",
3040
+ "header": "_5JdLea_header",
3041
+ "modelCandidateLabel": "_5JdLea_modelCandidateLabel",
3042
+ "editorSectionHeader": "_5JdLea_editorSectionHeader",
3009
3043
  "detectOk": "_5JdLea_detectOk",
3010
- "failed": "_5JdLea_failed",
3011
3044
  "modelArrow": "_5JdLea_modelArrow",
3012
- "spacer": "_5JdLea_spacer",
3013
- "modelCandidateLabel": "_5JdLea_modelCandidateLabel",
3014
- "pending": "_5JdLea_pending",
3015
- "channelMain": "_5JdLea_channelMain",
3016
- "body": "_5JdLea_body",
3017
- "description": "_5JdLea_description",
3018
- "label": "_5JdLea_label",
3045
+ "modelRowBadges": "_5JdLea_modelRowBadges",
3046
+ "presetRow": "_5JdLea_presetRow",
3047
+ "presetHint": "_5JdLea_presetHint",
3048
+ "manualModelRow": "_5JdLea_manualModelRow",
3019
3049
  "notExposed": "_5JdLea_notExposed",
3020
3050
  "hint": "_5JdLea_hint",
3021
- "modelRows": "_5JdLea_modelRows",
3022
- "sectionHeader": "_5JdLea_sectionHeader",
3023
- "channelControls": "_5JdLea_channelControls",
3024
- "presetName": "_5JdLea_presetName",
3051
+ "channelMain": "_5JdLea_channelMain",
3052
+ "body": "_5JdLea_body",
3053
+ "optionalContent": "_5JdLea_optionalContent",
3025
3054
  "channelSection": "_5JdLea_channelSection",
3026
- "sectionHint": "_5JdLea_sectionHint",
3027
- "presetMeta": "_5JdLea_presetMeta",
3028
- "editorTools": "_5JdLea_editorTools",
3029
- "modelRow": "_5JdLea_modelRow",
3030
- "name": "_5JdLea_name",
3055
+ "editorFooter": "_5JdLea_editorFooter",
3056
+ "modelRowInputs": "_5JdLea_modelRowInputs",
3057
+ "head": "_5JdLea_head",
3058
+ "pending": "_5JdLea_pending",
3059
+ "editorHeader": "_5JdLea_editorHeader",
3060
+ "channelControls": "_5JdLea_channelControls",
3061
+ "channelName": "_5JdLea_channelName",
3062
+ "readOnly": "_5JdLea_readOnly",
3031
3063
  "modelCandidate": "_5JdLea_modelCandidate",
3032
- "editorBackdrop": "_5JdLea_editorBackdrop",
3033
- "inlineDisclosure": "_5JdLea_inlineDisclosure",
3034
- "schemaSection": "_5JdLea_schemaSection",
3035
- "card": "_5JdLea_card",
3036
- "deleteConfirmText": "_5JdLea_deleteConfirmText",
3037
- "presetInline": "_5JdLea_presetInline",
3064
+ "channelAddRow": "_5JdLea_channelAddRow",
3038
3065
  "presetList": "_5JdLea_presetList",
3039
- "reset": "_5JdLea_reset",
3040
- "invalid": "_5JdLea_invalid",
3041
- "editorPanel": "_5JdLea_editorPanel",
3042
- "headText": "_5JdLea_headText",
3043
- "channelEmpty": "_5JdLea_channelEmpty",
3044
- "modelRowRemove": "_5JdLea_modelRowRemove",
3045
- "presetHint": "_5JdLea_presetHint",
3046
- "field": "_5JdLea_field",
3047
- "disclosure": "_5JdLea_disclosure",
3048
- "editorHeader": "_5JdLea_editorHeader",
3049
- "channelMeta": "_5JdLea_channelMeta",
3050
3066
  "modelCandidateList": "_5JdLea_modelCandidateList",
3051
- "channelRow": "_5JdLea_channelRow",
3052
- "header": "_5JdLea_header",
3067
+ "editorClose": "_5JdLea_editorClose",
3068
+ "spacer": "_5JdLea_spacer",
3069
+ "label": "_5JdLea_label",
3070
+ "field": "_5JdLea_field",
3071
+ "schemaSection": "_5JdLea_schemaSection",
3072
+ "sectionHeader": "_5JdLea_sectionHeader",
3053
3073
  "modelChip": "_5JdLea_modelChip",
3054
- "presetInlineHeader": "_5JdLea_presetInlineHeader",
3055
- "sectionTitle": "_5JdLea_sectionTitle",
3056
3074
  "modelSummary": "_5JdLea_modelSummary",
3057
- "footer": "_5JdLea_footer",
3058
- "channelAddRow": "_5JdLea_channelAddRow",
3059
- "channelList": "_5JdLea_channelList",
3060
- "channelName": "_5JdLea_channelName"
3075
+ "sectionTitle": "_5JdLea_sectionTitle",
3076
+ "modelRows": "_5JdLea_modelRows"
3061
3077
  };
3062
3078
  //#endregion
3063
3079
  //#region src/client/SettingsCard.tsx
@@ -3123,15 +3139,22 @@ window.__ModuleLoader__.load({
3123
3139
  * plugin's own interface precise instead of adding an index signature to it.
3124
3140
  */
3125
3141
  function asConfigFormHandle(scope) {
3142
+ let cachedFrom;
3143
+ let cached;
3144
+ const project = (snapshot) => ({
3145
+ status: snapshot.status,
3146
+ value: snapshot.value,
3147
+ writable: snapshot.writable,
3148
+ revision: snapshot.revision
3149
+ });
3126
3150
  return {
3127
3151
  getSnapshot() {
3128
3152
  const snapshot = scope.getSnapshot();
3129
- return {
3130
- status: snapshot.status,
3131
- value: snapshot.value,
3132
- writable: snapshot.writable,
3133
- revision: snapshot.revision
3134
- };
3153
+ if (snapshot !== cachedFrom) {
3154
+ cachedFrom = snapshot;
3155
+ cached = project(snapshot);
3156
+ }
3157
+ return cached;
3135
3158
  },
3136
3159
  subscribe(listener) {
3137
3160
  return scope.subscribe(listener);
@@ -3146,11 +3169,27 @@ window.__ModuleLoader__.load({
3146
3169
  scope;
3147
3170
  form;
3148
3171
  channelsForm;
3172
+ /**
3173
+ * The two face values that must keep their identity across `inject()` calls.
3174
+ *
3175
+ * The slot calls `inject()` on every render. Building either of these fresh
3176
+ * there changes the prop identity the renderer subscribed with, which
3177
+ * schedules another render, which calls `inject()` again — React reports that
3178
+ * as error #185 (`Maximum update depth exceeded`) and the slot renders as an
3179
+ * error node with no controls under it.
3180
+ */
3181
+ cardStore;
3182
+ schemaMirror;
3149
3183
  /** @param scope - the bound bridge scope for the dsh-imagegen namespace. */
3150
3184
  constructor(scope) {
3151
3185
  this.scope = scope;
3152
3186
  this.form = new CardForm(scope, [secretField("promptApiKey")], { secretSettled: (field) => this.scope.getSecretSetSnapshot(field) });
3153
3187
  this.channelsForm = new ChannelsForm(scope);
3188
+ this.schemaMirror = createSchemaMirror(scope);
3189
+ this.cardStore = this.form.bind(() => this.projection());
3190
+ this.channelsForm.subscribe(() => {
3191
+ this.cardStore.set(this.projection());
3192
+ });
3154
3193
  }
3155
3194
  projection() {
3156
3195
  const shell = this.form.shell();
@@ -3158,12 +3197,7 @@ window.__ModuleLoader__.load({
3158
3197
  ...shell,
3159
3198
  dirty: shell.dirty || this.channelsForm.snapshot().dirty,
3160
3199
  channels: this.channelsForm.snapshot(),
3161
- enabled: this.form.field("enabled"),
3162
- announceToAgent: this.form.field("announceToAgent"),
3163
- allowAgentImageGeneration: this.form.field("allowAgentImageGeneration"),
3164
- promptApiUrl: this.form.field("promptApiUrl"),
3165
- promptApiKey: this.form.field("promptApiKey"),
3166
- promptModel: this.form.field("promptModel")
3200
+ promptApiKey: this.form.field("promptApiKey")
3167
3201
  };
3168
3202
  }
3169
3203
  /**
@@ -3171,15 +3205,11 @@ window.__ModuleLoader__.load({
3171
3205
  * @returns the card's snapshot and the form/channel actions.
3172
3206
  */
3173
3207
  inject() {
3174
- const cardStore = this.form.bind(() => this.projection());
3175
- this.channelsForm.subscribe(() => {
3176
- cardStore.set(this.projection());
3177
- });
3178
3208
  return {
3179
- hooks: { imageGenSettingsCard: cardStore },
3209
+ hooks: { imageGenSettingsCard: this.cardStore },
3180
3210
  channels: this.channelsForm.actions(),
3181
3211
  settingsScope: this.scope,
3182
- schemaMirror: createSchemaMirror(this.scope),
3212
+ schemaMirror: this.schemaMirror,
3183
3213
  ...this.form.actions()
3184
3214
  };
3185
3215
  }
@@ -3202,6 +3232,7 @@ window.__ModuleLoader__.load({
3202
3232
  const t = tt;
3203
3233
  useImageGenLanguageTick();
3204
3234
  const state = props.useImageGenSettingsCard((snapshot) => snapshot);
3235
+ const formHandle = (0, react.useMemo)(() => asConfigFormHandle(props.settingsScope), [props.settingsScope]);
3205
3236
  const liveModel = props.settingsScope.getSnapshot().value?.promptModel ?? "";
3206
3237
  const [open, setOpen] = (0, react.useState)(false);
3207
3238
  const [promptModels, setPromptModels] = (0, react.useState)([]);
@@ -3302,7 +3333,7 @@ window.__ModuleLoader__.load({
3302
3333
  className: settings_card_module_css_default.schemaSection,
3303
3334
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_logictan_dsh_plugins_shared_client_client.ConfigForm, {
3304
3335
  namespace: IMAGEGEN_SETTINGS_NAMESPACE,
3305
- form: asConfigFormHandle(props.settingsScope),
3336
+ form: formHandle,
3306
3337
  describe: props.schemaMirror,
3307
3338
  title: t("settings.scalarsTitle"),
3308
3339
  children: [
@@ -4439,16 +4470,16 @@ window.__ModuleLoader__.load({
4439
4470
  document.head.appendChild(tag);
4440
4471
  }
4441
4472
  var image_toolview_module_css_default = {
4473
+ "images": "UtJPoq_images",
4474
+ "imageLink": "UtJPoq_imageLink",
4442
4475
  "image": "UtJPoq_image",
4443
- "status": "UtJPoq_status",
4476
+ "icon": "UtJPoq_icon",
4444
4477
  "message": "UtJPoq_message",
4478
+ "header": "UtJPoq_header",
4445
4479
  "loading": "UtJPoq_loading",
4446
- "images": "UtJPoq_images",
4447
- "imageLink": "UtJPoq_imageLink",
4448
4480
  "error": "UtJPoq_error",
4449
- "icon": "UtJPoq_icon",
4450
4481
  "root": "UtJPoq_root",
4451
- "header": "UtJPoq_header"
4482
+ "status": "UtJPoq_status"
4452
4483
  };
4453
4484
  //#endregion
4454
4485
  //#region src/client/image-toolview.tsx