@bubblydoo/uxp-toolkit 0.0.8 → 0.0.9

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.
Files changed (77) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/CHANGELOG.md +6 -0
  3. package/dist/{chunk-3CLJMC63.js → chunk-JBXCIUBZ.js} +49 -90
  4. package/dist/commands-library/index.d.ts +38 -39
  5. package/dist/commands-library/index.js +171 -171
  6. package/dist/index.d.ts +39 -41
  7. package/dist/index.js +189 -150
  8. package/dist/{psLayerRef-OY3h7srv.d.ts → psLayerRef-CGbTO4a5.d.ts} +36 -37
  9. package/package.json +8 -7
  10. package/src/commands-library/addLayerToSelection.ts +4 -4
  11. package/src/commands-library/applyLayerMask.ts +2 -2
  12. package/src/commands-library/convertMode.ts +2 -2
  13. package/src/commands-library/createColorLookupAdjustmentLayer.ts +2 -2
  14. package/src/commands-library/expandFolder.ts +4 -4
  15. package/src/commands-library/exportLUTs.ts +4 -4
  16. package/src/commands-library/getDocument.ts +7 -7
  17. package/src/commands-library/getLayer.ts +13 -13
  18. package/src/commands-library/hasVectorMask.ts +2 -2
  19. package/src/commands-library/index.ts +18 -18
  20. package/src/commands-library/loadLayerMaskAsSelection.ts +2 -2
  21. package/src/commands-library/multiGetDocument.ts +14 -14
  22. package/src/commands-library/rasterizeLayerStyle.ts +3 -3
  23. package/src/commands-library/rasterizeVectorMask.ts +2 -2
  24. package/src/commands-library/removeLayerMask.ts +2 -2
  25. package/src/commands-library/renameLayer.ts +6 -6
  26. package/src/commands-library/renameLayer.uxp-test.ts +13 -13
  27. package/src/commands-library/renderGrid.ts +2 -2
  28. package/src/commands-library/selectLayer.ts +3 -3
  29. package/src/commands-library/set3DLUTColorLookup.ts +2 -2
  30. package/src/core/batchPlay.ts +3 -3
  31. package/src/core/command.test-d.ts +11 -8
  32. package/src/core/command.ts +20 -23
  33. package/src/core/executeAsModal.ts +13 -11
  34. package/src/core/suspendHistory.ts +3 -3
  35. package/src/core/suspendHistory.uxp-test.ts +8 -8
  36. package/src/core-wrappers/executeAsModalAndSuspendHistory.ts +8 -6
  37. package/src/dom/getFlattenedDomLayersList.ts +6 -7
  38. package/src/dom/photoshopDomLayersToTree.ts +5 -5
  39. package/src/error-sourcemaps/sourcemaps.ts +23 -21
  40. package/src/error-sourcemaps/sourcemaps.uxp-test.ts +9 -8
  41. package/src/errors/ut-error.ts +2 -2
  42. package/src/filesystem/openFileByPath.ts +4 -4
  43. package/src/general-tree/flattenTree.ts +1 -1
  44. package/src/general-tree/layerRef.ts +2 -2
  45. package/src/general-tree/mapTree.ts +1 -1
  46. package/src/general-tree/mapTreeRef.ts +1 -1
  47. package/src/general-tree/treeTypes.ts +0 -2
  48. package/src/index.ts +43 -43
  49. package/src/metadata-storage/metadataStorage.ts +31 -31
  50. package/src/metadata-storage/metadataStorage.uxp-test.ts +11 -11
  51. package/src/node-compat/path/resolvePath.ts +6 -4
  52. package/src/other/applicationInfo.ts +11 -11
  53. package/src/other/applicationInfo.uxp-test.ts +6 -6
  54. package/src/other/clipboard.ts +2 -2
  55. package/src/other/clipboard.uxp-test.ts +9 -8
  56. package/src/other/uxpEntrypoints.ts +2 -2
  57. package/src/ut-tree/getDocumentLayerDescriptors.ts +6 -6
  58. package/src/ut-tree/getLayerEffects.ts +5 -5
  59. package/src/ut-tree/hasBackgroundLayer.uxp-test.ts +25 -23
  60. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.test.ts +29 -29
  61. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +62 -62
  62. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +29 -29
  63. package/src/ut-tree/psLayerRef.ts +2 -2
  64. package/src/ut-tree/utLayersToText.test.ts +32 -32
  65. package/src/ut-tree/utLayersToText.ts +19 -19
  66. package/src/ut-tree/utLayersToTree.ts +4 -4
  67. package/src/util/utLayerPickKeysType.ts +3 -3
  68. package/src/util/utLayerToLayer.ts +14 -13
  69. package/test/index.ts +11 -11
  70. package/test/meta-tests/builtinModules.uxp-test.ts +28 -26
  71. package/test/meta-tests/executeAsModal.uxp-test.ts +14 -12
  72. package/test/meta-tests/suspendHistory.uxp-test.ts +10 -9
  73. package/tsconfig.json +5 -5
  74. package/tsup.config.ts +5 -5
  75. package/uxp-tests.json +1 -1
  76. package/vitest-photoshop-alias-plugin.ts +23 -21
  77. package/vitest.config.ts +6 -6
@@ -1,6 +1,6 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
3
- import type { PsLayerRef } from "../ut-tree/psLayerRef";
1
+ import type { PsLayerRef } from '../ut-tree/psLayerRef';
2
+ import { z } from 'zod';
3
+ import { createCommand } from '../core/command';
4
4
 
5
5
  export function createExpandFolderCommand(layerRef: PsLayerRef) {
6
6
  return createCommand({
@@ -11,7 +11,7 @@ export function createExpandFolderCommand(layerRef: PsLayerRef) {
11
11
  _ref: [
12
12
  { _property: 'layerSectionExpanded' },
13
13
  { _ref: 'layer', _id: layerRef.id },
14
- { _ref: 'document', _id: layerRef.docId }
14
+ { _ref: 'document', _id: layerRef.docId },
15
15
  ],
16
16
  },
17
17
  to: true,
@@ -1,5 +1,5 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export type LUTExportFormat = 'CUBE' | 'ICC' | '3DL' | 'CSP';
5
5
 
@@ -13,7 +13,7 @@ export interface ExportLUTsOptions {
13
13
 
14
14
  export function createExportLUTsCommand(
15
15
  path: string,
16
- options: ExportLUTsOptions = {}
16
+ options: ExportLUTsOptions = {},
17
17
  ) {
18
18
  const {
19
19
  description = 'Exported LUT',
@@ -32,7 +32,7 @@ export function createExportLUTsCommand(
32
32
  $fpth: path,
33
33
  $dscr: description,
34
34
  $gPts: gridPoints,
35
- copyright: copyright,
35
+ copyright,
36
36
  $wICC: exportFormats.includes('ICC'),
37
37
  $w3DL: exportFormats.includes('3DL'),
38
38
  $wCUB: exportFormats.includes('CUBE'),
@@ -1,12 +1,12 @@
1
- import z from "zod";
2
- import { createCommand } from "../core/command";
1
+ import z from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export function createGetDocumentCommand(documentId: number) {
5
5
  return createCommand({
6
6
  modifying: false,
7
7
  descriptor: {
8
- _obj: "get",
9
- _target: { _ref: [{ _ref: "document", _id: documentId }] },
8
+ _obj: 'get',
9
+ _target: { _ref: [{ _ref: 'document', _id: documentId }] },
10
10
  },
11
11
  schema: z.object({
12
12
  title: z.string(),
@@ -21,11 +21,11 @@ export function createGetDocumentHasBackgroundLayerCommand(documentId: number) {
21
21
  return createCommand({
22
22
  modifying: false,
23
23
  descriptor: {
24
- _obj: "get",
24
+ _obj: 'get',
25
25
  _target: {
26
26
  _ref: [
27
- { _property: "hasBackgroundLayer" },
28
- { _ref: "document", _id: documentId },
27
+ { _property: 'hasBackgroundLayer' },
28
+ { _ref: 'document', _id: documentId },
29
29
  ],
30
30
  },
31
31
  },
@@ -1,6 +1,6 @@
1
- import z from "zod";
2
- import { createCommand } from "../core/command";
3
- import type { PsLayerRef } from "../ut-tree/psLayerRef";
1
+ import type { PsLayerRef } from '../ut-tree/psLayerRef';
2
+ import z from 'zod';
3
+ import { createCommand } from '../core/command';
4
4
 
5
5
  const layerSchema = z.object({
6
6
  name: z.string(),
@@ -8,17 +8,17 @@ const layerSchema = z.object({
8
8
  group: z.boolean(),
9
9
  layerSection: z.object({
10
10
  _value: z.enum([
11
- "layerSectionStart",
12
- "layerSectionEnd",
13
- "layerSectionContent",
11
+ 'layerSectionStart',
12
+ 'layerSectionEnd',
13
+ 'layerSectionContent',
14
14
  ]),
15
- _enum: z.literal("layerSectionType"),
15
+ _enum: z.literal('layerSectionType'),
16
16
  }),
17
17
  layerKind: z.number(),
18
18
  itemIndex: z.number(),
19
19
  background: z.boolean(),
20
20
  mode: z.object({
21
- _enum: z.literal("blendMode"),
21
+ _enum: z.literal('blendMode'),
22
22
  _value: z.string(),
23
23
  }),
24
24
  layerID: z.number(),
@@ -34,10 +34,10 @@ export function createGetLayerCommand(layerRef: PsLayerRef) {
34
34
  return createCommand({
35
35
  modifying: false,
36
36
  descriptor: {
37
- _obj: "get",
37
+ _obj: 'get',
38
38
  _target: [
39
- { _ref: "layer", _id: layerRef.id },
40
- { _ref: "document", _id: layerRef.docId },
39
+ { _ref: 'layer', _id: layerRef.id },
40
+ { _ref: 'document', _id: layerRef.docId },
41
41
  ],
42
42
  },
43
43
  schema: layerSchema,
@@ -48,8 +48,8 @@ export function createGetBackgroundLayerCommand(docId: number) {
48
48
  return createCommand({
49
49
  modifying: false,
50
50
  descriptor: {
51
- _obj: "get",
52
- _target: { _ref: [{ _ref: "layer", "_property": "background" }, { _ref: "document", _id: docId }] },
51
+ _obj: 'get',
52
+ _target: { _ref: [{ _ref: 'layer', _property: 'background' }, { _ref: 'document', _id: docId }] },
53
53
  },
54
54
  schema: layerSchema,
55
55
  });
@@ -1,5 +1,5 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export function createHasVectorMaskCommand(layerId: number) {
5
5
  return createCommand({
@@ -1,29 +1,29 @@
1
- // Layer selection and manipulation
2
- export * from './selectLayer';
3
1
  export * from './addLayerToSelection';
4
- export * from './expandFolder';
5
-
6
- // Layer operations
7
- export * from './getLayer';
8
- export * from './renameLayer';
9
- export * from './rasterizeLayerStyle';
10
- export * from './rasterizeVectorMask';
11
-
12
2
  // Layer mask operations
13
3
  export * from './applyLayerMask';
14
- export * from './removeLayerMask';
15
- export * from './loadLayerMaskAsSelection';
16
- export * from './hasVectorMask';
17
-
18
- // Document operations
19
- export * from './getDocument';
20
- export * from './multiGetDocument';
21
4
  export * from './convertMode';
22
5
 
23
6
  // Color and LUT operations
24
7
  export * from './createColorLookupAdjustmentLayer';
25
- export * from './set3DLUTColorLookup';
8
+ export * from './expandFolder';
26
9
  export * from './exportLUTs';
10
+ // Document operations
11
+ export * from './getDocument';
12
+
13
+ // Layer operations
14
+ export * from './getLayer';
15
+ export * from './hasVectorMask';
16
+ export * from './loadLayerMaskAsSelection';
17
+ export * from './multiGetDocument';
27
18
 
19
+ export * from './rasterizeLayerStyle';
20
+ export * from './rasterizeVectorMask';
21
+ export * from './removeLayerMask';
22
+
23
+ export * from './renameLayer';
28
24
  // Other
29
25
  export * from './renderGrid';
26
+ // Layer selection and manipulation
27
+ export * from './selectLayer';
28
+
29
+ export * from './set3DLUTColorLookup';
@@ -1,5 +1,5 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export function createLoadLayerMaskAsSelectionCommand(layerId: number) {
5
5
  return createCommand({
@@ -1,15 +1,15 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export function createMultiGetDocumentCommand(docId: number) {
5
5
  return createCommand({
6
6
  modifying: false,
7
7
  descriptor: {
8
- _obj: "multiGet",
9
- _target: { _ref: [{ _ref: "document", _id: docId }] },
8
+ _obj: 'multiGet',
9
+ _target: { _ref: [{ _ref: 'document', _id: docId }] },
10
10
  extendedReference: [
11
- ["name", "layerID", "visible", "group", "layerSection", "layerKind", "itemIndex", "background", "mode", "layerEffects"],
12
- { _obj: "layer", index: 1, count: -1 },
11
+ ['name', 'layerID', 'visible', 'group', 'layerSection', 'layerKind', 'itemIndex', 'background', 'mode', 'layerEffects'],
12
+ { _obj: 'layer', index: 1, count: -1 },
13
13
  ],
14
14
  },
15
15
  schema: z.object({
@@ -21,17 +21,17 @@ export function createMultiGetDocumentCommand(docId: number) {
21
21
  group: z.boolean(),
22
22
  layerSection: z.object({
23
23
  _value: z.enum([
24
- "layerSectionStart",
25
- "layerSectionEnd",
26
- "layerSectionContent",
24
+ 'layerSectionStart',
25
+ 'layerSectionEnd',
26
+ 'layerSectionContent',
27
27
  ]),
28
- _enum: z.literal("layerSectionType"),
28
+ _enum: z.literal('layerSectionType'),
29
29
  }),
30
30
  layerKind: z.number(),
31
31
  itemIndex: z.number(),
32
32
  background: z.boolean(),
33
33
  mode: z.object({
34
- _enum: z.literal("blendMode"),
34
+ _enum: z.literal('blendMode'),
35
35
  _value: z.string(),
36
36
  }),
37
37
  layerEffects: z.record(z.string(), z.object({
@@ -40,8 +40,8 @@ export function createMultiGetDocumentCommand(docId: number) {
40
40
  }).or(z.array(z.object({
41
41
  enabled: z.boolean(),
42
42
  })))).optional(),
43
- })
44
- )
45
- })
43
+ }),
44
+ ),
45
+ }),
46
46
  });
47
47
  }
@@ -1,6 +1,6 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
3
- import type { PsLayerRef } from "../ut-tree/psLayerRef";
1
+ import type { PsLayerRef } from '../ut-tree/psLayerRef';
2
+ import { z } from 'zod';
3
+ import { createCommand } from '../core/command';
4
4
 
5
5
  export function createRasterizeLayerStyleCommand(psLayerRef: PsLayerRef) {
6
6
  return createCommand({
@@ -1,5 +1,5 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export function createRasterizeVectorMaskCommand() {
5
5
  return createCommand({
@@ -1,5 +1,5 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export function createDeleteChannelCommand() {
5
5
  return createCommand({
@@ -1,14 +1,14 @@
1
- import { createCommand } from "../core/command";
2
- import type { PsLayerRef } from "../ut-tree/psLayerRef";
3
- import { z } from "zod";
1
+ import type { PsLayerRef } from '../ut-tree/psLayerRef';
2
+ import { z } from 'zod';
3
+ import { createCommand } from '../core/command';
4
4
 
5
5
  export function createRenameLayerCommand(layerRef: PsLayerRef, newName: string) {
6
6
  return createCommand({
7
7
  modifying: true,
8
8
  descriptor: {
9
- _obj: "set",
10
- _target: [{ _ref: "layer", _id: layerRef.id }, { _ref: "document", _id: layerRef.docId }],
11
- to: { _obj: "layer", name: newName },
9
+ _obj: 'set',
10
+ _target: [{ _ref: 'layer', _id: layerRef.id }, { _ref: 'document', _id: layerRef.docId }],
11
+ to: { _obj: 'layer', name: newName },
12
12
  },
13
13
  schema: z.unknown(),
14
14
  });
@@ -1,10 +1,10 @@
1
- import { executeAsModal } from "../core/executeAsModal";
2
- import { openFileByPath } from "../filesystem/openFileByPath";
3
- import { getDocumentLayerDescriptors } from "../ut-tree/getDocumentLayerDescriptors";
4
- import type { Test } from "@bubblydoo/uxp-test-framework";
5
- import { expect } from "chai";
6
- import { app } from "photoshop";
7
- import { createRenameLayerCommand } from "./renameLayer";
1
+ import type { Test } from '@bubblydoo/uxp-test-framework';
2
+ import { expect } from 'chai';
3
+ import { app } from 'photoshop';
4
+ import { executeAsModal } from '../core/executeAsModal';
5
+ import { openFileByPath } from '../filesystem/openFileByPath';
6
+ import { getDocumentLayerDescriptors } from '../ut-tree/getDocumentLayerDescriptors';
7
+ import { createRenameLayerCommand } from './renameLayer';
8
8
 
9
9
  async function getFirstLayer() {
10
10
  const allLayers = await getDocumentLayerDescriptors(app.activeDocument.id);
@@ -18,15 +18,15 @@ async function getFirstLayer() {
18
18
  }
19
19
 
20
20
  export const renameLayerTest: Test = {
21
- name: "Rename Layer",
21
+ name: 'Rename Layer',
22
22
  async run() {
23
- await openFileByPath("plugin:/fixtures/one-layer.psd");
23
+ await openFileByPath('plugin:/fixtures/one-layer.psd');
24
24
  const layer = await getFirstLayer();
25
- expect(layer.name).to.equal("Layer 1");
26
- await executeAsModal("Rename Layer", async (ctx) => {
27
- await ctx.batchPlayCommand(createRenameLayerCommand(layer.ref, "New Name"));
25
+ expect(layer.name).to.equal('Layer 1');
26
+ await executeAsModal('Rename Layer', async (ctx) => {
27
+ await ctx.batchPlayCommand(createRenameLayerCommand(layer.ref, 'New Name'));
28
28
  });
29
29
  const layer2 = await getFirstLayer();
30
- expect(layer2.name).to.equal("New Name");
30
+ expect(layer2.name).to.equal('New Name');
31
31
  },
32
32
  };
@@ -1,5 +1,5 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export function createRenderGridCommand(gridPoints: number) {
5
5
  return createCommand({
@@ -1,6 +1,6 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
3
- import type { PsLayerRef } from "../ut-tree/psLayerRef";
1
+ import type { PsLayerRef } from '../ut-tree/psLayerRef';
2
+ import { z } from 'zod';
3
+ import { createCommand } from '../core/command';
4
4
 
5
5
  export function createSelectLayerCommand(layerRef: PsLayerRef) {
6
6
  return createCommand({
@@ -1,5 +1,5 @@
1
- import { z } from "zod";
2
- import { createCommand } from "../core/command";
1
+ import { z } from 'zod';
2
+ import { createCommand } from '../core/command';
3
3
 
4
4
  export type LUTFormatType = 'LUTFormatCUBE' | 'LUTFormat3DL' | 'LUTFormatCSP';
5
5
 
@@ -1,4 +1,4 @@
1
- import { action } from "photoshop";
1
+ import { action } from 'photoshop';
2
2
 
3
3
  type P = Parameters<typeof action.batchPlay>;
4
4
 
@@ -9,8 +9,8 @@ export type CorrectBatchPlayOptions = P[1] & {
9
9
  export async function batchPlay(actions: P[0], options?: CorrectBatchPlayOptions) {
10
10
  return action.batchPlay(actions, {
11
11
  ...options,
12
- modalBehavior: "execute",
13
- dialogOptions: "silent",
12
+ modalBehavior: 'execute',
13
+ dialogOptions: 'silent',
14
14
  synchronousExecution: false,
15
15
  });
16
16
  }
@@ -1,14 +1,16 @@
1
- import { describe, expectTypeOf, test } from "vitest";
2
- import { z } from "zod";
1
+ /* eslint-disable unused-imports/no-unused-vars */
2
+ import type { UTCommandResult } from './command';
3
+ import { describe, expectTypeOf, test } from 'vitest';
4
+ import { z } from 'zod';
3
5
  import {
4
6
  createCommand,
5
- type UTCommandResult,
6
- } from "./command";
7
7
 
8
- describe("UTCommandResult type tests", () => {
9
- test("extracts result type from non-modifying command", () => {
8
+ } from './command';
9
+
10
+ describe('UTCommandResult type tests', () => {
11
+ test('extracts result type from non-modifying command', () => {
10
12
  const command = createCommand({
11
- descriptor: { _obj: "get" },
13
+ descriptor: { _obj: 'get' },
12
14
  schema: z.object({
13
15
  name: z.string(),
14
16
  count: z.number(),
@@ -22,4 +24,5 @@ describe("UTCommandResult type tests", () => {
22
24
  name: string;
23
25
  count: number;
24
26
  }>();
25
- });});
27
+ });
28
+ });
@@ -1,29 +1,26 @@
1
- import type { ActionDescriptor } from "photoshop/dom/CoreModules";
2
- import { z } from "zod";
3
- import { batchPlay } from "./batchPlay";
4
- import { executeAsModal } from "./executeAsModal";
5
- import type { CorrectExecutionContext } from "./executeAsModal";
6
- import { action } from "photoshop";
7
-
8
- export interface UTCommandBase<T extends any> {
1
+ import type { ActionDescriptor } from 'photoshop';
2
+ import type { z } from 'zod';
3
+ import { batchPlay } from './batchPlay';
4
+
5
+ export interface UTCommandBase<T> {
9
6
  descriptor: ActionDescriptor;
10
7
  schema: z.ZodSchema<T>;
11
8
  }
12
9
 
13
- export interface UTCommandModifying<T extends any> extends UTCommandBase<T> {
10
+ export interface UTCommandModifying<T> extends UTCommandBase<T> {
14
11
  modifying: true;
15
12
  }
16
13
 
17
- export interface UTCommandNonModifying<T extends any> extends UTCommandBase<T> {
14
+ export interface UTCommandNonModifying<T> extends UTCommandBase<T> {
18
15
  modifying: false;
19
16
  }
20
17
 
21
- export function createCommand<TReturn extends any, TModifying extends boolean>(
18
+ export function createCommand<TReturn, TModifying extends boolean>(
22
19
  obj: {
23
- descriptor: ActionDescriptor,
24
- schema: z.ZodSchema<TReturn>,
25
- modifying: TModifying,
26
- }
20
+ descriptor: ActionDescriptor;
21
+ schema: z.ZodSchema<TReturn>;
22
+ modifying: TModifying;
23
+ },
27
24
  ): TModifying extends true ? UTCommandModifying<TReturn> : UTCommandNonModifying<TReturn> {
28
25
  return {
29
26
  modifying: obj.modifying,
@@ -36,28 +33,28 @@ export type UTCommandResult<C> = C extends UTCommandBase<infer T> ? T : never;
36
33
 
37
34
  type BatchPlayOptions = Parameters<typeof batchPlay>[1];
38
35
 
39
- async function batchPlayCommandBase<T extends any>(command: UTCommandBase<T>, options?: BatchPlayOptions) {
36
+ async function batchPlayCommandBase<T>(command: UTCommandBase<T>, options?: BatchPlayOptions) {
40
37
  const [result] = await batchPlay([command.descriptor], options);
41
- if (result?._obj === "error") {
42
- throw new Error("Batch play command failed", { cause: result });
38
+ if (result?._obj === 'error') {
39
+ throw new Error('Batch play command failed', { cause: result });
43
40
  }
44
41
  return command.schema.parse(result);
45
42
  }
46
43
 
47
44
  async function batchPlayCommandsBase<TCommands extends Array<UTCommandBase<any>>>(
48
45
  commands: readonly [...TCommands],
49
- options?: BatchPlayOptions
46
+ options?: BatchPlayOptions,
50
47
  ): Promise<{
51
48
  [K in keyof TCommands]: UTCommandResult<TCommands[K]>;
52
49
  }> {
53
50
  const results = await batchPlay(commands.map(command => command.descriptor), options);
54
- if (results[0]?._obj === "error") {
55
- throw new Error("Batch play command failed", { cause: results[0] });
51
+ if (results[0]?._obj === 'error') {
52
+ throw new Error('Batch play command failed', { cause: results[0] });
56
53
  }
57
54
  return commands.map((command, index) => command.schema.parse(results[index])) as any;
58
55
  }
59
56
 
60
- export function batchPlayCommand<T extends any>(command: UTCommandNonModifying<T>, options?: BatchPlayOptions) {
57
+ export function batchPlayCommand<T>(command: UTCommandNonModifying<T>, options?: BatchPlayOptions) {
61
58
  return batchPlayCommandBase(command, options);
62
59
  }
63
60
 
@@ -69,7 +66,7 @@ export function createModifyingBatchPlayContext() {
69
66
  return {
70
67
  batchPlayCommand: batchPlayCommandBase,
71
68
  batchPlayCommands: batchPlayCommandsBase,
72
- }
69
+ };
73
70
  }
74
71
  // some examples:
75
72
 
@@ -1,5 +1,5 @@
1
- import { core } from "photoshop";
2
- import { createModifyingBatchPlayContext } from "./command";
1
+ import { core } from 'photoshop';
2
+ import { createModifyingBatchPlayContext } from './command';
3
3
 
4
4
  // copied from devtools:
5
5
  // hostControl: {suspendHistory: ƒ, resumeHistory: ƒ, registerAutoCloseDocument: ƒ, unregisterAutoCloseDocument: ƒ}
@@ -12,7 +12,7 @@ import { createModifyingBatchPlayContext } from "./command";
12
12
  // reportProgress: ƒ ()
13
13
  // resolve: ƒ ()
14
14
 
15
- export type CorrectExecutionContext = {
15
+ export interface CorrectExecutionContext {
16
16
  /**
17
17
  * True if user has cancelled the modal interaction.
18
18
  *
@@ -38,8 +38,8 @@ export type CorrectExecutionContext = {
38
38
  * Call to suspend history on a target document, returns the suspension ID which can be used for resumeHistory
39
39
  */
40
40
  suspendHistory: (info: {
41
- documentID: number,
42
- name: string,
41
+ documentID: number;
42
+ name: string;
43
43
  }) => Promise<number>;
44
44
  /**
45
45
  * Call to resume history on a target document
@@ -52,19 +52,19 @@ export type CorrectExecutionContext = {
52
52
  };
53
53
  }
54
54
 
55
- export type CorrectExecuteAsModalOptions = {
55
+ export interface CorrectExecuteAsModalOptions {
56
56
  commandName: string;
57
57
  interactive?: boolean;
58
58
  timeOut?: number;
59
59
  }
60
60
 
61
- export type ExtendedExecutionContext = Omit<CorrectExecutionContext, "onCancel"> & ReturnType<typeof createModifyingBatchPlayContext> & {
61
+ export type ExtendedExecutionContext = Omit<CorrectExecutionContext, 'onCancel'> & ReturnType<typeof createModifyingBatchPlayContext> & {
62
62
  signal: AbortSignal;
63
63
  };
64
64
 
65
65
  const originalExecuteAsModal: <T>(fn: (executionContext: CorrectExecutionContext) => Promise<void>, opts: CorrectExecuteAsModalOptions) => Promise<T> = core.executeAsModal as any;
66
66
 
67
- type OptionsWithoutCommandName = Omit<CorrectExecuteAsModalOptions, "commandName">;
67
+ type OptionsWithoutCommandName = Omit<CorrectExecuteAsModalOptions, 'commandName'>;
68
68
 
69
69
  export async function executeAsModal<T>(commandName: string, fn: (executionContext: ExtendedExecutionContext) => Promise<T>, opts?: OptionsWithoutCommandName): Promise<T> {
70
70
  let error: unknown;
@@ -84,8 +84,9 @@ export async function executeAsModal<T>(commandName: string, fn: (executionConte
84
84
  };
85
85
  try {
86
86
  result = await fn(extendedExecutionContext);
87
- } catch (e) {
88
- console.error("error in executeAsModal");
87
+ }
88
+ catch (e) {
89
+ console.error('error in executeAsModal');
89
90
  console.error(e);
90
91
  error = e;
91
92
  }
@@ -95,7 +96,8 @@ export async function executeAsModal<T>(commandName: string, fn: (executionConte
95
96
  });
96
97
  if (error) {
97
98
  throw error;
98
- } else {
99
+ }
100
+ else {
99
101
  return result!;
100
102
  }
101
103
  }
@@ -1,11 +1,11 @@
1
- import type { Document } from "photoshop/dom/Document";
1
+ import type { Document } from 'photoshop';
2
2
 
3
3
  // The Adobe provided type is wrong
4
- export type SuspendHistoryContext = {};
4
+ export interface SuspendHistoryContext {}
5
5
  export async function suspendHistory<T>(
6
6
  document: Document,
7
7
  historyStateName: string,
8
- fn: (context: SuspendHistoryContext) => Promise<T>
8
+ fn: (context: SuspendHistoryContext) => Promise<T>,
9
9
  ): Promise<T> {
10
10
  let result: T | undefined;
11
11
  await document.suspendHistory(async (context) => {
@@ -1,18 +1,18 @@
1
- import type { Test } from "@bubblydoo/uxp-test-framework";
2
- import { expect } from "chai";
3
- import { suspendHistory } from "./suspendHistory";
4
- import { app } from "photoshop";
1
+ import type { Test } from '@bubblydoo/uxp-test-framework';
2
+ import { expect } from 'chai';
3
+ import { app } from 'photoshop';
4
+ import { suspendHistory } from './suspendHistory';
5
5
 
6
6
  export const suspendHistoryTest: Test = {
7
- name: "core/suspendHistory should return correctly",
7
+ name: 'core/suspendHistory should return correctly',
8
8
  async run() {
9
9
  const document = app.activeDocument;
10
10
  if (!document) {
11
- throw new Error("No active document");
11
+ throw new Error('No active document');
12
12
  }
13
- const result = await suspendHistory(document, "Test", async (context) => {
13
+ const result = await suspendHistory(document, 'Test', async (context) => {
14
14
  return 'test';
15
15
  });
16
16
  expect(result).to.equal('test');
17
17
  },
18
- };
18
+ };