@spiffcommerce/core 0.9.10 → 0.10.1

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/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Workflow as _Workflow1, StepAspect as _StepAspect1, Step as _Step1, AnyStepData as _AnyStepData1, FrameOffsets, PatternImageData, IServerModel, Asset as _Asset1, MaterialResource, AssetType as _AssetType1, ColorDefinition as _ColorDefinition1, IllustrationStepData as _IllustrationStepData1, Region, ILayout as _ILayout1, CreateElementCommand as _CreateElementCommand1, IllustrationElement as _IllustrationElement1, LayoutsState as _LayoutsState1, VariantResource as _VariantResource1, CanvasCommand as _CanvasCommand1, LayoutData as _LayoutData1, DigitalContentStepData as _DigitalContentStepData1, FrameStepData as _FrameStepData1, FrameElement as _FrameElement1, MaterialStepData as _MaterialStepData1, ModelStepData as _ModelStepData1, ModuleStepData as _ModuleStepData1, PatchworkStepData as _PatchworkStepData1, PatchworkOffsets as _PatchworkOffsets1, PictureStepData as _PictureStepData1, QuestionStepData as _QuestionStepData1, ShapeStepData as _ShapeStepData1, FontData, GroupCommand as _GroupCommand1, OptionResource as _OptionResource1, TextboxElement as _TextboxElement1, TextStepData as _TextStepData1, StepStorage as _StepStorage1, SerializableStep, CommandState as _CommandState1, LayoutState, CommandContext as _CommandContext1, Point, ScaleAxis, UnitOfMeasurement as _UnitOfMeasurement1, StepType as _StepType1, Animatable, AnyStepData, Asset, AssetType, BringForwardCommand, BulkStepData, CanvasCommand, ColorDefinition, CommandContext, CommandState, CreateElementCommand, DeleteElementCommand, DigitalContentStepData, FontAlignmentCommand, FontColorCommand, FontSizeCommand, FontSourceCommand, FrameElement, FrameStepData, GroupCommand, ILayout, IllustrationElement, IllustrationStepData, ImageElement, LayoutData, LayoutElement, LayoutElementFactory, LayoutElementType, LayoutsState, MaterialStepData, ModelStepData, ModuleStepData, MoveCommand, OptionResource, PatchworkElement, PatchworkOffsets, PatchworkStepData, PictureStepData, QuestionStepData, ResizeCommand, RotateCommand, SendBackwardsCommand, ShapeStepData, Step, StepAspect, StepAspectType, StepStorage, StepType, TextChangeCommand, TextStepData, TextboxElement, UnitOfMeasurement, VariantResource, Workflow, dataUrlFromExternalUrl, findElement, frameDataCache, generate, generateSVGWithUnknownColors, getAttributesFromArrayBuffer, getFrameData, getSvgString, loadFontFromDataUrl, loadFontFromExternalUrl, patternImageDataCache, CreateLayoutCommand, rehydrateSerializedLayout, ColorProfileProps, WorkflowPanel, determineCorrectFontSizeAndLines, registerJSDOM } from "@spiffcommerce/papyrus";
1
+ import { Workflow as _Workflow1, StepAspect as _StepAspect1, Step as _Step1, AnyStepData as _AnyStepData1, FrameOffsets, PatternImageData, IServerModel, Asset as _Asset1, MaterialResource, AssetType as _AssetType1, VariantResource as _VariantResource1, ColorDefinition as _ColorDefinition1, IllustrationStepData as _IllustrationStepData1, Region, ILayout as _ILayout1, CreateElementCommand as _CreateElementCommand1, IllustrationElement as _IllustrationElement1, LayoutsState as _LayoutsState1, CanvasCommand as _CanvasCommand1, LayoutData as _LayoutData1, DigitalContentStepData as _DigitalContentStepData1, FrameStepData as _FrameStepData1, FrameElement as _FrameElement1, MaterialStepData as _MaterialStepData1, ModelStepData as _ModelStepData1, ModuleStepData as _ModuleStepData1, PatchworkStepData as _PatchworkStepData1, PatchworkOffsets as _PatchworkOffsets1, PictureStepData as _PictureStepData1, QuestionStepData as _QuestionStepData1, ShapeStepData as _ShapeStepData1, FontData, GroupCommand as _GroupCommand1, OptionResource as _OptionResource1, TextboxElement as _TextboxElement1, TextStepData as _TextStepData1, StepStorage as _StepStorage1, SerializableStep, CommandState as _CommandState1, CommandContext as _CommandContext1, LayoutState, Point, ScaleAxis, UnitOfMeasurement as _UnitOfMeasurement1, StepType as _StepType1, Animatable, AnyStepData, Asset, AssetType, BringForwardCommand, BulkStepData, CanvasCommand, ColorDefinition, CommandContext, CommandState, CreateElementCommand, DeleteElementCommand, DigitalContentStepData, FontAlignmentCommand, FontColorCommand, FontSizeCommand, FontSourceCommand, FrameElement, FrameStepData, GroupCommand, ILayout, IllustrationElement, IllustrationStepData, ImageElement, LayoutData, LayoutElement, LayoutElementFactory, LayoutElementType, LayoutsState, MaterialStepData, ModelStepData, ModuleStepData, MoveCommand, OptionResource, PatchworkElement, PatchworkOffsets, PatchworkStepData, PictureStepData, QuestionStepData, ResizeCommand, RotateCommand, SendBackwardsCommand, ShapeStepData, Step, StepAspect, StepAspectType, StepStorage, StepType, TextChangeCommand, TextStepData, TextboxElement, UnitOfMeasurement, VariantResource, Workflow, dataUrlFromExternalUrl, findElement, frameDataCache, generate, generateSVGWithUnknownColors, getAttributesFromArrayBuffer, getFrameData, getSvgString, loadFontFromDataUrl, loadFontFromExternalUrl, patternImageDataCache, CreateLayoutCommand, rehydrateSerializedLayout, ColorProfileProps, WorkflowPanel, determineCorrectFontSizeAndLines, registerJSDOM } from "@spiffcommerce/papyrus";
2
2
  import { ApolloClient } from "@apollo/client";
3
3
  import { ReactNode, Dispatch, FunctionComponent, RefObject, PointerEvent, KeyboardEvent, MouseEvent } from "react";
4
4
  export const gatherVaryingStepAspects: (workflow: _Workflow1) => _StepAspect1[];
@@ -208,6 +208,13 @@ declare class AssetService {
208
208
  * Convert a File object for an image into a FileInfo.
209
209
  */
210
210
  loadImageAsFileInfo: (file: File) => Promise<FileInfo>;
211
+ /**
212
+ * Search for the asset of a variant. First looks for an asset inlined in the variant,
213
+ * otherwise check for ID in our cache and go to the server as a last resort.
214
+ * @param variant The variant to search on.
215
+ * @returns An asset entity as a promise.
216
+ */
217
+ getAssetFromVariant: (variant: _VariantResource1) => Promise<IServerModel<_Asset1>>;
211
218
  }
212
219
  interface PersistedAsset {
213
220
  assetKey: string;
@@ -235,7 +242,7 @@ declare class IllustrationStepService implements StepService<_IllustrationStepDa
235
242
  }[];
236
243
  changeColorsCommand(svg: string, illustrationWidth: number, illustrationHeight: number, elements: string[], newFills: Map<string, string>): Promise<_CanvasCommand1>;
237
244
  changeColors(stepData: _Step1<_IllustrationStepData1>, elements: RegionElement[], workflowManager: WorkflowManager, getAllLayouts: () => _LayoutData1[], newFills: Map<string, string>): Promise<void>;
238
- selectVariant(stepData: _Step1<_IllustrationStepData1>, variant: _VariantResource1, elements: RegionElement[], setIsUpdating: (isUpdating: boolean) => void, workflowManager: WorkflowManager): void;
245
+ selectVariant(stepData: _Step1<_IllustrationStepData1>, variant: _VariantResource1, elements: RegionElement[], setIsUpdating: (isUpdating: boolean) => void, workflowManager: WorkflowManager): Promise<void>;
239
246
  }
240
247
  export const svgObjectURL: (svg: string) => Promise<string>;
241
248
  export const illustrationStepService: IllustrationStepService;
@@ -348,7 +355,7 @@ declare class TextStepService implements StepService<_TextStepData1> {
348
355
  */
349
356
  filterUnsupportedCharacters: (text: string, fontData?: FontData) => string;
350
357
  updateInputText(input: string, elements: _TextboxElement1[], step: _Step1<_TextStepData1>, workflowManager: WorkflowManager): TextUpdateResult;
351
- selectVariant(step: _Step1<_TextStepData1>, variant: _VariantResource1, storage: TextStepStorage, elements: RegionElement[], workflowManager: WorkflowManager, setError: (status: boolean) => void, setHelperText: (text: string) => void): void;
358
+ selectVariant(step: _Step1<_TextStepData1>, variant: _VariantResource1, workflowManager: WorkflowManager, setError: (status: boolean) => void, setHelperText: (text: string) => void): void;
352
359
  textAlign: (stepData: _TextStepData1) => string;
353
360
  createTextFillSpotColor(colorOption: IServerModel<_OptionResource1>, variant: _VariantResource1): TextFillSpotColor | undefined;
354
361
  }
@@ -400,7 +407,8 @@ export interface InformationResult {
400
407
  }
401
408
  export enum InformationMessageType {
402
409
  Error = "Error",
403
- Warning = "Warning"
410
+ Warning = "Warning",
411
+ Info = "Info"
404
412
  }
405
413
  /**
406
414
  * Services required for the operaiton of individual steps.
@@ -449,6 +457,7 @@ export interface WorkflowManager {
449
457
  getCommandDispatcher: () => (command: _CanvasCommand1) => void;
450
458
  getCurrentVariationRecord: () => VariationRecord | undefined;
451
459
  getVariationRecords: () => VariationRecord[];
460
+ getCommandContext: () => _CommandContext1;
452
461
  getLayouts: () => _ILayout1[];
453
462
  getAllLayoutData: () => LayoutState[];
454
463
  getLayoutPreviewService: () => any;
@@ -842,6 +851,13 @@ declare class OptionService {
842
851
  * Returns all selected variants. This is used by the question step as multiple selections can be made.
843
852
  */
844
853
  getSelectedVariants: (option: _OptionResource1 | undefined, selectedVariantIds: string[]) => _VariantResource1[];
854
+ /**
855
+ * Returns the option from a given step. When the option is inline, we return that.
856
+ * Otherwise look for an option ID, check our cache and go to the server as a last resort.
857
+ * @param step The step to find an option on.
858
+ * @returns An OptionResource in a promise.
859
+ */
860
+ getOptionFromStep: (step: _Step1<_AnyStepData1>) => Promise<IServerModel<_OptionResource1>>;
845
861
  }
846
862
  export const optionService: OptionService;
847
863
  export const CommandContextContext: import("react").Context<_CommandContext1>;
@@ -1048,56 +1064,45 @@ export const AdvancedEditor: FunctionComponent<{
1048
1064
  onElementSelected?: (id: string | undefined, element: PointerEvent) => void;
1049
1065
  }>;
1050
1066
  /**
1051
- * An abstract base class to be extended by step handles to implement type specific behavior.
1067
+ * A StepHandle allows for managing the state of a specific step in a workflow. This class
1068
+ * abstracts away the complexities of dealing with a step directly and allows for using high level
1069
+ * concepts instead of dealing with the underlying data structures.
1052
1070
  */
1053
- declare abstract class StepHandleTypeContext<T> {
1071
+ declare abstract class StepHandle<T extends _AnyStepData1> {
1072
+ /**
1073
+ * Access to the workflow manager this step is contained by.
1074
+ */
1054
1075
  protected readonly manager: WorkflowManager;
1076
+ /**
1077
+ * The step metadata, useful for determining logic based on configuration.
1078
+ */
1055
1079
  protected readonly step: _Step1<T>;
1056
- constructor(manager: WorkflowManager, stepConfiguration: _Step1<T>);
1057
- }
1058
- interface TextChangeResult {
1059
- input: string;
1060
- helperText?: string;
1061
- errorText?: string;
1062
- }
1063
- declare class StepHandleTextContext extends StepHandleTypeContext<_TextStepData1> {
1080
+ constructor(manager: WorkflowManager, step: _Step1<T>);
1064
1081
  /**
1065
- * Changes the fill of text related to this step to the new fill value.
1066
- * @param fill A new fill value to use.
1082
+ * Set the current update state of this step. All step handles pointing to this step will
1083
+ * see this value.
1084
+ * @param value The new value
1067
1085
  */
1068
- setFill(fill: ColorOption): Promise<void>;
1086
+ protected setUpdateState(value: boolean): void;
1069
1087
  /**
1070
- * Changes the text value of text related to this step to a new value.
1071
- * @param userInput Input from the user.
1088
+ * @returns Gets the current update state of this step. All step handles for this step will see this value.
1072
1089
  */
1073
- setText(userInput: string): TextChangeResult;
1074
- }
1075
- /**
1076
- * A StepHandle allows for managing the state of a specific step in a workflow. This class
1077
- * abstracts away the complexities of dealing with a step directly and allows for using high level
1078
- * concepts instead of dealing with the underlying data structures.
1079
- */
1080
- interface StepHandle {
1090
+ protected getUpdateState(): boolean;
1081
1091
  /**
1082
1092
  * Gets the currently selected variant, or undefined if no variant is selected.
1083
1093
  */
1084
- getCurrentVariant(): any;
1094
+ getCurrentVariant(): _VariantResource1;
1085
1095
  /**
1086
1096
  * Returns a list of valid variants for this step.
1087
1097
  */
1088
1098
  getAvailableVariants(): Promise<_VariantResource1[]>;
1089
1099
  /**
1090
- * Selects a specific variant for this step.
1091
- */
1092
- selectVariant(variant: _VariantResource1): any;
1093
- /**
1094
- * Get a handle to a class that exposes any functionality specific to this step type.
1100
+ * Most step types have a base option type that variants can be selected for.
1101
+ * Selects a specific variant for this step. This will execute all required changes to
1102
+ * the design and update the metadata to include the new selection. Any conditions
1103
+ * that would be triggered will also be executed.
1095
1104
  */
1096
- getTypeSpecificContext(): StepHandleTextContext | StepHandleIllustrationContext | StepHandleQuestionContext;
1097
- }
1098
- declare class StepHandleIllustrationContext extends StepHandleTypeContext<_IllustrationStepData1> {
1099
- }
1100
- declare class StepHandleQuestionContext extends StepHandleTypeContext<_QuestionStepData1> {
1105
+ abstract selectVariant(variant: _VariantResource1): Promise<void>;
1101
1106
  }
1102
1107
  /**
1103
1108
  * A Workflow experience encapsulates the workflow manager and command context. It
@@ -1125,17 +1130,17 @@ export interface WorkflowExperience {
1125
1130
  * Returns the step matching a given name, undefined if not found.
1126
1131
  * @param id The id the step must match.
1127
1132
  */
1128
- getStepById(id: string): StepHandle | undefined;
1133
+ getStepById(id: string): StepHandle<_AnyStepData1> | undefined;
1129
1134
  /**
1130
1135
  * Returns the step matching a given name, undefined if not found.
1131
1136
  * @param name The name the step must match.
1132
1137
  */
1133
- getStepByName(name: string): StepHandle | undefined;
1138
+ getStepByName(name: string): StepHandle<_AnyStepData1> | undefined;
1134
1139
  /**
1135
1140
  * Returns all steps matching a specific type in the workflow. These steps
1136
1141
  * may be across multiple scenes and may or may not be active based on condition state.
1137
1142
  */
1138
- getStepsByType(type: _StepType1): StepHandle[];
1143
+ getStepsByType(type: _StepType1): StepHandle<_AnyStepData1>[];
1139
1144
  /**
1140
1145
  * Creates a data URL preview for the current design.
1141
1146
  */
@@ -1210,6 +1215,7 @@ export class Client {
1210
1215
  getTransaction(): Transaction;
1211
1216
  }
1212
1217
  export class MockWorkflowManager implements WorkflowManager {
1218
+ getCommandContext: () => _CommandContext1;
1213
1219
  getAllLayoutData: () => LayoutState[];
1214
1220
  getMetadata: (stepName: string) => StepMetadata | undefined;
1215
1221
  getStepStorage: (stepName: string) => _StepStorage1 | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "0.9.10",
3
+ "version": "0.10.1",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@apollo/client": "^3.7.0",
82
- "@spiffcommerce/papyrus": "^1.5.4",
82
+ "@spiffcommerce/papyrus": "^1.5.5",
83
83
  "canvg": "https://github.com/spiffdev/canvg.git#03bcd151b12441e88ecb552bb658356f5bbe92c4",
84
84
  "cross-fetch": "^3.1.5",
85
85
  "graphql": "^16.6.0",