@bubblydoo/uxp-toolkit 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-3CLJMC63.js → chunk-JBXCIUBZ.js} +49 -90
- package/dist/commands-library/index.d.ts +38 -39
- package/dist/commands-library/index.js +171 -171
- package/dist/index.d.ts +41 -83
- package/dist/index.js +203 -152
- package/dist/{psLayerRef-OY3h7srv.d.ts → psLayerRef-CGbTO4a5.d.ts} +36 -37
- package/package.json +9 -7
- package/src/commands-library/addLayerToSelection.ts +4 -4
- package/src/commands-library/applyLayerMask.ts +2 -2
- package/src/commands-library/convertMode.ts +2 -2
- package/src/commands-library/createColorLookupAdjustmentLayer.ts +2 -2
- package/src/commands-library/expandFolder.ts +4 -4
- package/src/commands-library/exportLUTs.ts +4 -4
- package/src/commands-library/getDocument.ts +7 -7
- package/src/commands-library/getLayer.ts +13 -13
- package/src/commands-library/hasVectorMask.ts +2 -2
- package/src/commands-library/index.ts +18 -18
- package/src/commands-library/loadLayerMaskAsSelection.ts +2 -2
- package/src/commands-library/multiGetDocument.ts +14 -14
- package/src/commands-library/rasterizeLayerStyle.ts +3 -3
- package/src/commands-library/rasterizeVectorMask.ts +2 -2
- package/src/commands-library/removeLayerMask.ts +2 -2
- package/src/commands-library/renameLayer.ts +6 -6
- package/src/commands-library/renameLayer.uxp-test.ts +13 -13
- package/src/commands-library/renderGrid.ts +2 -2
- package/src/commands-library/selectLayer.ts +3 -3
- package/src/commands-library/set3DLUTColorLookup.ts +2 -2
- package/src/core/batchPlay.ts +3 -3
- package/src/core/command.test-d.ts +11 -8
- package/src/core/command.ts +20 -23
- package/src/core/executeAsModal.ts +11 -67
- package/src/core/suspendHistory.ts +3 -3
- package/src/core/suspendHistory.uxp-test.ts +8 -8
- package/src/core-wrappers/executeAsModalAndSuspendHistory.ts +8 -6
- package/src/dom/getFlattenedDomLayersList.ts +6 -7
- package/src/dom/photoshopDomLayersToTree.ts +5 -5
- package/src/error-sourcemaps/sourcemaps.ts +27 -26
- package/src/error-sourcemaps/sourcemaps.uxp-test.ts +9 -8
- package/src/errors/ut-error.ts +2 -2
- package/src/filesystem/isFileOrFolder.ts +9 -0
- package/src/filesystem/openFileByPath.ts +10 -6
- package/src/general-tree/flattenTree.ts +1 -1
- package/src/general-tree/layerRef.ts +2 -2
- package/src/general-tree/mapTree.ts +1 -1
- package/src/general-tree/mapTreeRef.ts +1 -1
- package/src/general-tree/treeTypes.ts +0 -2
- package/src/index.ts +42 -43
- package/src/metadata-storage/metadataStorage.ts +31 -31
- package/src/metadata-storage/metadataStorage.uxp-test.ts +11 -11
- package/src/node-compat/path/resolvePath.ts +6 -4
- package/src/other/applicationInfo.ts +11 -11
- package/src/other/applicationInfo.uxp-test.ts +6 -6
- package/src/other/clipboard.ts +2 -2
- package/src/other/clipboard.uxp-test.ts +9 -8
- package/src/other/uxpEntrypoints.ts +2 -2
- package/src/ut-tree/getDocumentLayerDescriptors.ts +6 -6
- package/src/ut-tree/getLayerEffects.ts +5 -5
- package/src/ut-tree/hasBackgroundLayer.uxp-test.ts +25 -23
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.test.ts +29 -29
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +62 -62
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +29 -29
- package/src/ut-tree/psLayerRef.ts +2 -2
- package/src/ut-tree/utLayersToText.test.ts +32 -32
- package/src/ut-tree/utLayersToText.ts +19 -19
- package/src/ut-tree/utLayersToTree.ts +4 -4
- package/src/util/utLayerPickKeysType.ts +3 -3
- package/src/util/utLayerToLayer.ts +14 -13
- package/test/index.ts +11 -11
- package/test/meta-tests/builtinModules.uxp-test.ts +28 -26
- package/test/meta-tests/executeAsModal.uxp-test.ts +14 -12
- package/test/meta-tests/suspendHistory.uxp-test.ts +10 -9
- package/tsconfig.json +5 -5
- package/tsup.config.ts +5 -5
- package/typedoc.json +6 -0
- package/uxp-tests.json +1 -1
- package/vitest-photoshop-alias-plugin.ts +23 -21
- package/vitest.config.ts +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
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
|
|
2
|
-
import { createCommand } from
|
|
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
|
|
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
|
|
2
|
-
import { createCommand } from
|
|
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:
|
|
9
|
-
_target: { _ref: [{ _ref:
|
|
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:
|
|
24
|
+
_obj: 'get',
|
|
25
25
|
_target: {
|
|
26
26
|
_ref: [
|
|
27
|
-
{ _property:
|
|
28
|
-
{ _ref:
|
|
27
|
+
{ _property: 'hasBackgroundLayer' },
|
|
28
|
+
{ _ref: 'document', _id: documentId },
|
|
29
29
|
],
|
|
30
30
|
},
|
|
31
31
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
'layerSectionStart',
|
|
12
|
+
'layerSectionEnd',
|
|
13
|
+
'layerSectionContent',
|
|
14
14
|
]),
|
|
15
|
-
_enum: z.literal(
|
|
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(
|
|
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:
|
|
37
|
+
_obj: 'get',
|
|
38
38
|
_target: [
|
|
39
|
-
{ _ref:
|
|
40
|
-
{ _ref:
|
|
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:
|
|
52
|
-
_target: { _ref: [{ _ref:
|
|
51
|
+
_obj: 'get',
|
|
52
|
+
_target: { _ref: [{ _ref: 'layer', _property: 'background' }, { _ref: 'document', _id: docId }] },
|
|
53
53
|
},
|
|
54
54
|
schema: layerSchema,
|
|
55
55
|
});
|
|
@@ -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 './
|
|
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,15 +1,15 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { createCommand } from
|
|
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:
|
|
9
|
-
_target: { _ref: [{ _ref:
|
|
8
|
+
_obj: 'multiGet',
|
|
9
|
+
_target: { _ref: [{ _ref: 'document', _id: docId }] },
|
|
10
10
|
extendedReference: [
|
|
11
|
-
[
|
|
12
|
-
{ _obj:
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
'layerSectionStart',
|
|
25
|
+
'layerSectionEnd',
|
|
26
|
+
'layerSectionContent',
|
|
27
27
|
]),
|
|
28
|
-
_enum: z.literal(
|
|
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(
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
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,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
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:
|
|
10
|
-
_target: [{ _ref:
|
|
11
|
-
to: { _obj:
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { createRenameLayerCommand } from
|
|
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:
|
|
21
|
+
name: 'Rename Layer',
|
|
22
22
|
async run() {
|
|
23
|
-
await openFileByPath(
|
|
23
|
+
await openFileByPath('plugin:/fixtures/one-layer.psd');
|
|
24
24
|
const layer = await getFirstLayer();
|
|
25
|
-
expect(layer.name).to.equal(
|
|
26
|
-
await executeAsModal(
|
|
27
|
-
await ctx.batchPlayCommand(createRenameLayerCommand(layer.ref,
|
|
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(
|
|
30
|
+
expect(layer2.name).to.equal('New Name');
|
|
31
31
|
},
|
|
32
32
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
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({
|
package/src/core/batchPlay.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { action } from
|
|
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:
|
|
13
|
-
dialogOptions:
|
|
12
|
+
modalBehavior: 'execute',
|
|
13
|
+
dialogOptions: 'silent',
|
|
14
14
|
synchronousExecution: false,
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
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:
|
|
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
|
+
});
|
package/src/core/command.ts
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import type { ActionDescriptor } from
|
|
2
|
-
import { z } from
|
|
3
|
-
import { batchPlay } from
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
10
|
+
export interface UTCommandModifying<T> extends UTCommandBase<T> {
|
|
14
11
|
modifying: true;
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
export interface UTCommandNonModifying<T
|
|
14
|
+
export interface UTCommandNonModifying<T> extends UTCommandBase<T> {
|
|
18
15
|
modifying: false;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
export function createCommand<TReturn
|
|
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
|
|
36
|
+
async function batchPlayCommandBase<T>(command: UTCommandBase<T>, options?: BatchPlayOptions) {
|
|
40
37
|
const [result] = await batchPlay([command.descriptor], options);
|
|
41
|
-
if (result?._obj ===
|
|
42
|
-
throw new Error(
|
|
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 ===
|
|
55
|
-
throw new Error(
|
|
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
|
|
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,75 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ExecuteAsModalOptions, ExecutionContext } from 'photoshop';
|
|
2
|
+
import { core } from 'photoshop';
|
|
3
|
+
import { createModifyingBatchPlayContext } from './command';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
// hostControl: {suspendHistory: ƒ, resumeHistory: ƒ, registerAutoCloseDocument: ƒ, unregisterAutoCloseDocument: ƒ}
|
|
6
|
-
// mode: "action"
|
|
7
|
-
// uiMode: "never"
|
|
8
|
-
// finalizeArguments: ƒ ()
|
|
9
|
-
// isCancelled: undefined
|
|
10
|
-
// onCancel: undefined
|
|
11
|
-
// reject: ƒ ()
|
|
12
|
-
// reportProgress: ƒ ()
|
|
13
|
-
// resolve: ƒ ()
|
|
14
|
-
|
|
15
|
-
export type CorrectExecutionContext = {
|
|
16
|
-
/**
|
|
17
|
-
* True if user has cancelled the modal interaction.
|
|
18
|
-
*
|
|
19
|
-
* User can cancel by hitting the Escape key, or by pressing the "Cancel" button in the progress bar.
|
|
20
|
-
*/
|
|
21
|
-
isCancelled: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* If assigned a method, it will be called when user cancels the modal interaction.
|
|
24
|
-
*/
|
|
25
|
-
onCancel: () => void;
|
|
26
|
-
/**
|
|
27
|
-
* Call this to customize the progress bar.
|
|
28
|
-
*/
|
|
29
|
-
reportProgress: (info: {
|
|
30
|
-
value: number;
|
|
31
|
-
commandName?: string;
|
|
32
|
-
}) => void;
|
|
33
|
-
/**
|
|
34
|
-
* Use the methods in here to control Photoshop state
|
|
35
|
-
*/
|
|
36
|
-
hostControl: {
|
|
37
|
-
/**
|
|
38
|
-
* Call to suspend history on a target document, returns the suspension ID which can be used for resumeHistory
|
|
39
|
-
*/
|
|
40
|
-
suspendHistory: (info: {
|
|
41
|
-
documentID: number,
|
|
42
|
-
name: string,
|
|
43
|
-
}) => Promise<number>;
|
|
44
|
-
/**
|
|
45
|
-
* Call to resume history on a target document
|
|
46
|
-
*/
|
|
47
|
-
resumeHistory: (suspensionID: number, commit: boolean) => Promise<void>;
|
|
48
|
-
/** Register a document to be closed when the modal scope exits. See below for details. */
|
|
49
|
-
registerAutoCloseDocument: (documentID: number) => Promise<void>;
|
|
50
|
-
/** Unregister a document from being closed when the modal scope exits */
|
|
51
|
-
unregisterAutoCloseDocument: (documentID: number) => Promise<void>;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export type CorrectExecuteAsModalOptions = {
|
|
56
|
-
commandName: string;
|
|
57
|
-
interactive?: boolean;
|
|
58
|
-
timeOut?: number;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export type ExtendedExecutionContext = Omit<CorrectExecutionContext, "onCancel"> & ReturnType<typeof createModifyingBatchPlayContext> & {
|
|
5
|
+
export type ExtendedExecutionContext = Omit<ExecutionContext, 'onCancel'> & ReturnType<typeof createModifyingBatchPlayContext> & {
|
|
62
6
|
signal: AbortSignal;
|
|
63
7
|
};
|
|
64
8
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
type OptionsWithoutCommandName = Omit<CorrectExecuteAsModalOptions, "commandName">;
|
|
9
|
+
type OptionsWithoutCommandName = Omit<ExecuteAsModalOptions, 'commandName'>;
|
|
68
10
|
|
|
69
11
|
export async function executeAsModal<T>(commandName: string, fn: (executionContext: ExtendedExecutionContext) => Promise<T>, opts?: OptionsWithoutCommandName): Promise<T> {
|
|
70
12
|
let error: unknown;
|
|
71
13
|
let result: T;
|
|
72
|
-
await
|
|
14
|
+
await core.executeAsModal(async (executionContext) => {
|
|
73
15
|
const abortController = new AbortController();
|
|
74
16
|
executionContext.onCancel = () => {
|
|
75
17
|
abortController.abort();
|
|
@@ -84,8 +26,9 @@ export async function executeAsModal<T>(commandName: string, fn: (executionConte
|
|
|
84
26
|
};
|
|
85
27
|
try {
|
|
86
28
|
result = await fn(extendedExecutionContext);
|
|
87
|
-
}
|
|
88
|
-
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error('error in executeAsModal');
|
|
89
32
|
console.error(e);
|
|
90
33
|
error = e;
|
|
91
34
|
}
|
|
@@ -95,7 +38,8 @@ export async function executeAsModal<T>(commandName: string, fn: (executionConte
|
|
|
95
38
|
});
|
|
96
39
|
if (error) {
|
|
97
40
|
throw error;
|
|
98
|
-
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
99
43
|
return result!;
|
|
100
44
|
}
|
|
101
45
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Document } from
|
|
1
|
+
import type { Document } from 'photoshop';
|
|
2
2
|
|
|
3
3
|
// The Adobe provided type is wrong
|
|
4
|
-
export
|
|
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) => {
|