Skip to content

Commit ddeb99b

Browse files
New layer spacing ports; Delay 1 node; StitchPosition refactor (#104)
Co-authored-by: Chris Clampitt <christian.clampitt@nyu.edu>
1 parent 80c5937 commit ddeb99b

128 files changed

Lines changed: 6029 additions & 221 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Sources/StitchSchemaKit/SchemaVersionUtil.swift

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protocol StitchSchemaVersionable {
1313
static var version: StitchSchemaVersion { get }
1414
}
1515

16-
protocol StitchSchemaVersionType {
16+
public protocol StitchSchemaVersionType {
1717
associatedtype NewestVersionType: StitchVersionedCodable
1818

1919
var version: StitchSchemaVersion { get }
@@ -55,7 +55,35 @@ extension URL {
5555
}
5656
}
5757

58-
extension StitchDocumentVersion {
58+
public protocol VersionType: CaseIterable, Codable, Comparable, RawRepresentable {}
59+
60+
extension VersionType where RawValue: Comparable {
61+
public static func < (a: Self, b: Self) -> Bool {
62+
return a.rawValue < b.rawValue
63+
}
64+
}
65+
66+
public struct StitchDocumentVersion: StitchSchemaVersionType {
67+
public typealias NewestVersionType = CurrentStitchDocument.StitchDocument
68+
69+
public var version: StitchSchemaVersion
70+
71+
public init(version: StitchSchemaVersion) {
72+
self.version = version
73+
}
74+
}
75+
76+
public struct StitchComonentVersion: StitchSchemaVersionType {
77+
public typealias NewestVersionType = CurrentStitchComponent.StitchComponent
78+
79+
public var version: StitchSchemaVersion
80+
81+
public init(version: StitchSchemaVersion) {
82+
self.version = version
83+
}
84+
}
85+
86+
extension StitchSchemaVersionType {
5987
public static func migrate(versionedCodableUrl: URL) throws -> Self.NewestVersionType? {
6088
// 1. get version
6189
// 2. call decode with payload
@@ -92,10 +120,6 @@ extension StitchDocumentVersion {
92120
}
93121

94122
extension StitchVersionedCodable {
95-
// static func createVersionedEntities(from models: [Self.ViewModel]) -> [Self] {
96-
// models.map { Self.init(from: $0) }
97-
// }
98-
99123
public static func upgradeEntities(_ previousEntities: [Self.PreviousCodable]) -> [Self] {
100124
previousEntities.map { Self.init(previousInstance: $0) }
101125
}
@@ -123,18 +147,7 @@ extension Array where Element: StitchVersionedCodable {
123147

124148
self = .init(previousInstance: previousInstance)
125149
}
126-
}
127-
128-
// extension StitchVersionedData {
129-
// /// Initializer that uses current version.
130-
// public init(currentDoc: StitchDocument) throws {
131-
// let encoder = getStitchEncoder()
132-
// let encodedDoc = try encoder.encode(currentDoc)
133-
134-
// self.version = StitchSchemaVersion.getNewestVersion()
135-
// self.data = encodedDoc
136-
// }
137-
// }
150+
}
138151

139152
public protocol StitchVersionedCodable: Codable, Sendable {
140153
associatedtype PreviousCodable: StitchVersionedCodable

Sources/StitchSchemaKit/SchemaVersions.swift

Lines changed: 106 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -9,96 +9,98 @@ import Foundation
99
import SwiftUI
1010

1111
// MARK: - UPDATE VERSION NUMBERS HERE
12-
public typealias CurrentAsyncMediaValue = AsyncMediaValue_V23
13-
public typealias CurrentClassicAnimationCurve = ClassicAnimationCurve_V23
14-
public typealias CurrentCameraSettings = CameraSettings_V23
15-
public typealias CurrentCommentBoxData = CommentBoxData_V23
16-
public typealias CurrentCustomShape = CustomShape_V23
17-
public typealias CurrentDataType = DataType_V23
18-
public typealias CurrentDelayStyle = DelayStyle_V23
19-
public typealias CurrentDateAndTimeFormat = DateAndTimeFormat_V23
20-
public typealias CurrentExpansionDirection = ExpansionDirection_V23
21-
public typealias CurrentGroupNodeIDCoordinate = GroupNodeID_V23
22-
public typealias CurrentPatch = Patch_V23
23-
public typealias CurrentPatchNodeEntity = PatchNodeEntity_V23
24-
public typealias CurrentLayerDimension = LayerDimension_V23
25-
public typealias CurrentLayerNodeEntity = LayerNodeEntity_V23
26-
public typealias CurrentLayerNodeId = LayerNodeId_V23
27-
public typealias CurrentNodeEntity = NodeEntity_V23
28-
public typealias CurrentNodePortInputEntity = NodePortInputEntity_V23
29-
public typealias CurrentSplitterNodeEntity = SplitterNodeEntity_V23
30-
public typealias CurrentSplitterType = SplitterType_V23
31-
public typealias CurrentNodeIOCoordinate = NodeIOCoordinate_V23
32-
public typealias CurrentJSONCurveTo = JSONCurveTo_V23
33-
public typealias CurrentJSONShapeCommand = JSONShapeCommand_V23
34-
public typealias CurrentJSONShapeKeys = JSONShapeKeys_V23
35-
public typealias CurrentSidebarLayerData = SidebarLayerData_V23
36-
public typealias CurrentNodeKind = NodeKind_V23
37-
public typealias CurrentAnchoring = Anchoring_V23
38-
public typealias CurrentCameraDirection = CameraDirection_V23
39-
public typealias CurrentLayer = Layer_V23
40-
public typealias CurrentLayerSize = LayerSize_V23
41-
public typealias CurrentLayerTextDecoration = LayerTextDecoration_V23
42-
public typealias CurrentLayerStroke = LayerStroke_V23
43-
public typealias CurrentLayerTextAlignment = LayerTextAlignment_V23
44-
public typealias CurrentLayerTextVerticalAlignment = LayerTextVerticalAlignment_V23
45-
public typealias CurrentLightType = LightType_V23
46-
public typealias CurrentMediaKey = MediaKey_V23
47-
public typealias CurrentMobileHapticStyle = MobileHapticStyle_V23
48-
public typealias CurrentNetworkRequestType = NetworkRequestType_V23
49-
public typealias CurrentPathPoint = PathPoint_V23
50-
public typealias CurrentPlane = Plane_V23
51-
public typealias CurrentPoint3D = Point3D_V23
52-
public typealias CurrentPoint4D = Point4D_V23
53-
public typealias CurrentPortValueComparable = PortValueComparable_V23
54-
public typealias CurrentPreviewSize = PreviewSize_V23
55-
public typealias CurrentRGBA = RGBA_V23
56-
public typealias CurrentRoundedRectangleData = RoundedRectangleData_V23
57-
public typealias CurrentScrollDecelerationRate = ScrollDecelerationRate_V23
58-
public typealias CurrentScrollJumpStyle = ScrollJumpStyle_V23
59-
public typealias CurrentScrollMode = ScrollMode_V23
60-
public typealias CurrentShapeCommand = ShapeCommand_V23
61-
public typealias CurrentShapeCommandType = ShapeCommandType_V23
62-
public typealias CurrentShapeCoordinates = ShapeCoordinates_V23
63-
public typealias CurrentShapeAndRect = ShapeAndRect_V23
64-
public typealias CurrentStitchDocument = StitchDocument_V23
65-
public typealias CurrentStitchBlendMode = StitchBlendMode_V23
66-
public typealias CurrentStitchCameraOrientation = StitchCameraOrientation_V23
67-
public typealias CurrentStitchDeviceOrientation = StitchDeviceOrientation_V23
68-
public typealias CurrentStitchMapType = StitchMapType_V23
69-
public typealias CurrentStitchFont = StitchFont_V23
70-
public typealias CurrentStitchFontChoice = StitchFontChoice_V23
71-
public typealias CurrentStitchFontWeight = StitchFontWeight_V23
72-
public typealias CurrentStitchJSON = StitchJSON_V23
73-
public typealias CurrentStitchOrientation = StitchOrientation_V23
74-
public typealias CurrentStitchProgressIndicatorStyle = ProgressIndicatorStyle_V23
75-
public typealias CurrentTextTransform = TextTransform_V23
76-
public typealias CurrentTriangleData = TriangleData_V23
77-
public typealias CurrentPortValue = PortValue_V23
78-
public typealias CurrentUserVisibleType = UserVisibleType_V23
79-
public typealias CurrentVisualMediaFitStyle = VisualMediaFitStyle_V23
80-
public typealias CurrentNodeConnectionType = NodeConnectionType_V23
81-
public typealias CurrentLayerInputType = LayerInputType_V23
82-
public typealias CurrentNodeIOPortType = NodeIOPortType_V23
83-
public typealias CurrentStrokeLineCap = StrokeLineCap_V23
84-
public typealias CurrentStrokeLineJoin = StrokeLineJoin_V23
85-
public typealias CurrentStitchStringValue = StitchStringValue_V23
86-
public typealias CurrentStitchContentMode = StitchContentMode_V23
87-
public typealias CurrentStitchSpacing = StitchSpacing_V23
88-
public typealias CurrentStitchPadding = StitchPadding_V23
89-
public typealias CurrentSizingScenario = SizingScenario_V23
90-
public typealias CurrentNodeTypeEntity = NodeTypeEntity_V23
91-
public typealias CurrentCanvasNodeEntity = CanvasNodeEntity_V23
92-
public typealias CurrentLayerInputDataEntity = LayerInputDataEntity_V23
93-
public typealias CurrentCanvasItemId = CanvasItemId_V23
94-
public typealias CurrentLayerInputCoordinate = LayerInputCoordinate_V23
95-
public typealias CurrentLayerOutputCoordinate = LayerOutputCoordinate_V23
96-
public typealias CurrentPinToId = PinToId_V23
97-
public typealias CurrentLayerInputEntity = LayerInputEntity_V23
98-
public typealias CurrentLayerInputPort = LayerInputPort_V23
99-
public typealias CurrentLayerInputKeyPathType = LayerInputKeyPathType_V23
100-
public typealias CurrentUnpackedPortType = UnpackedPortType_V23
101-
public typealias CurrentStitchTransform = StitchTransform_V23
12+
public typealias CurrentAsyncMediaValue = AsyncMediaValue_V24
13+
public typealias CurrentClassicAnimationCurve = ClassicAnimationCurve_V24
14+
public typealias CurrentCameraSettings = CameraSettings_V24
15+
public typealias CurrentCommentBoxData = CommentBoxData_V24
16+
public typealias CurrentCustomShape = CustomShape_V24
17+
public typealias CurrentDataType = DataType_V24
18+
public typealias CurrentDelayStyle = DelayStyle_V24
19+
public typealias CurrentDateAndTimeFormat = DateAndTimeFormat_V24
20+
public typealias CurrentExpansionDirection = ExpansionDirection_V24
21+
public typealias CurrentGroupNodeIDCoordinate = GroupNodeID_V24
22+
public typealias CurrentPatch = Patch_V24
23+
public typealias CurrentPatchNodeEntity = PatchNodeEntity_V24
24+
public typealias CurrentLayerDimension = LayerDimension_V24
25+
public typealias CurrentLayerNodeEntity = LayerNodeEntity_V24
26+
public typealias CurrentLayerNodeId = LayerNodeId_V24
27+
public typealias CurrentNodeEntity = NodeEntity_V24
28+
public typealias CurrentNodePortInputEntity = NodePortInputEntity_V24
29+
public typealias CurrentSplitterNodeEntity = SplitterNodeEntity_V24
30+
public typealias CurrentSplitterType = SplitterType_V24
31+
public typealias CurrentNodeIOCoordinate = NodeIOCoordinate_V24
32+
public typealias CurrentJSONCurveTo = JSONCurveTo_V24
33+
public typealias CurrentJSONShapeCommand = JSONShapeCommand_V24
34+
public typealias CurrentJSONShapeKeys = JSONShapeKeys_V24
35+
public typealias CurrentSidebarLayerData = SidebarLayerData_V24
36+
public typealias CurrentNodeKind = NodeKind_V24
37+
public typealias CurrentAnchoring = Anchoring_V24
38+
public typealias CurrentCameraDirection = CameraDirection_V24
39+
public typealias CurrentLayer = Layer_V24
40+
public typealias CurrentLayerSize = LayerSize_V24
41+
public typealias CurrentLayerTextDecoration = LayerTextDecoration_V24
42+
public typealias CurrentLayerStroke = LayerStroke_V24
43+
public typealias CurrentLayerTextAlignment = LayerTextAlignment_V24
44+
public typealias CurrentLayerTextVerticalAlignment = LayerTextVerticalAlignment_V24
45+
public typealias CurrentLightType = LightType_V24
46+
public typealias CurrentMediaKey = MediaKey_V24
47+
public typealias CurrentMobileHapticStyle = MobileHapticStyle_V24
48+
public typealias CurrentNetworkRequestType = NetworkRequestType_V24
49+
public typealias CurrentPathPoint = PathPoint_V24
50+
public typealias CurrentPlane = Plane_V24
51+
public typealias CurrentPoint3D = Point3D_V24
52+
public typealias CurrentPoint4D = Point4D_V24
53+
public typealias CurrentPortValueComparable = PortValueComparable_V24
54+
public typealias CurrentPreviewSize = PreviewSize_V24
55+
public typealias CurrentRGBA = RGBA_V24
56+
public typealias CurrentRoundedRectangleData = RoundedRectangleData_V24
57+
public typealias CurrentScrollDecelerationRate = ScrollDecelerationRate_V24
58+
public typealias CurrentScrollJumpStyle = ScrollJumpStyle_V24
59+
public typealias CurrentScrollMode = ScrollMode_V24
60+
public typealias CurrentShapeCommand = ShapeCommand_V24
61+
public typealias CurrentShapeCommandType = ShapeCommandType_V24
62+
public typealias CurrentShapeCoordinates = ShapeCoordinates_V24
63+
public typealias CurrentShapeAndRect = ShapeAndRect_V24
64+
public typealias CurrentStitchDocument = StitchDocument_V24
65+
public typealias CurrentStitchBlendMode = StitchBlendMode_V24
66+
public typealias CurrentStitchCameraOrientation = StitchCameraOrientation_V24
67+
public typealias CurrentStitchDeviceOrientation = StitchDeviceOrientation_V24
68+
public typealias CurrentStitchMapType = StitchMapType_V24
69+
public typealias CurrentStitchFont = StitchFont_V24
70+
public typealias CurrentStitchFontChoice = StitchFontChoice_V24
71+
public typealias CurrentStitchFontWeight = StitchFontWeight_V24
72+
public typealias CurrentStitchJSON = StitchJSON_V24
73+
public typealias CurrentStitchOrientation = StitchOrientation_V24
74+
public typealias CurrentStitchProgressIndicatorStyle = ProgressIndicatorStyle_V24
75+
public typealias CurrentTextTransform = TextTransform_V24
76+
public typealias CurrentTriangleData = TriangleData_V24
77+
public typealias CurrentPortValue = PortValue_V24
78+
public typealias CurrentUserVisibleType = UserVisibleType_V24
79+
public typealias CurrentVisualMediaFitStyle = VisualMediaFitStyle_V24
80+
public typealias CurrentNodeConnectionType = NodeConnectionType_V24
81+
public typealias CurrentLayerInputType = LayerInputType_V24
82+
public typealias CurrentNodeIOPortType = NodeIOPortType_V24
83+
public typealias CurrentStrokeLineCap = StrokeLineCap_V24
84+
public typealias CurrentStrokeLineJoin = StrokeLineJoin_V24
85+
public typealias CurrentStitchStringValue = StitchStringValue_V24
86+
public typealias CurrentStitchContentMode = StitchContentMode_V24
87+
public typealias CurrentStitchSpacing = StitchSpacing_V24
88+
public typealias CurrentStitchPadding = StitchPadding_V24
89+
public typealias CurrentSizingScenario = SizingScenario_V24
90+
public typealias CurrentNodeTypeEntity = NodeTypeEntity_V24
91+
public typealias CurrentCanvasNodeEntity = CanvasNodeEntity_V24
92+
public typealias CurrentLayerInputDataEntity = LayerInputDataEntity_V24
93+
public typealias CurrentCanvasItemId = CanvasItemId_V24
94+
public typealias CurrentLayerInputCoordinate = LayerInputCoordinate_V24
95+
public typealias CurrentLayerOutputCoordinate = LayerOutputCoordinate_V24
96+
public typealias CurrentPinToId = PinToId_V24
97+
public typealias CurrentLayerInputEntity = LayerInputEntity_V24
98+
public typealias CurrentLayerInputPort = LayerInputPort_V24
99+
public typealias CurrentLayerInputKeyPathType = LayerInputKeyPathType_V24
100+
public typealias CurrentUnpackedPortType = UnpackedPortType_V24
101+
public typealias CurrentStitchTransform = StitchTransform_V24
102+
public typealias CurrentStitchComponent = StitchComponent_V24
103+
102104
// MARK: - end
103105

104106
public enum StitchSchemaVersion: Int, VersionType {
@@ -125,24 +127,7 @@ public enum StitchSchemaVersion: Int, VersionType {
125127
case _V21 = 21
126128
case _V22 = 22
127129
case _V23 = 23
128-
}
129-
130-
public protocol VersionType: CaseIterable, Codable, Comparable, RawRepresentable {}
131-
132-
extension VersionType where RawValue: Comparable {
133-
public static func < (a: Self, b: Self) -> Bool {
134-
return a.rawValue < b.rawValue
135-
}
136-
}
137-
138-
public struct StitchDocumentVersion: StitchSchemaVersionType {
139-
public typealias NewestVersionType = CurrentStitchDocument.StitchDocument
140-
141-
public var version: StitchSchemaVersion
142-
143-
public init(version: StitchSchemaVersion) {
144-
self.version = version
145-
}
130+
case _V24 = 24
146131
}
147132

148133
extension StitchDocumentVersion {
@@ -194,46 +179,20 @@ extension StitchDocumentVersion {
194179
return StitchDocument_V22.StitchDocument.self
195180
case ._V23:
196181
return StitchDocument_V23.StitchDocument.self
182+
case ._V24:
183+
return StitchDocument_V24.StitchDocument.self
197184
}
198185
}
199186
}
200187

201-
// extension CurrentStitchDocument.StitchDocument_Codable {
202-
// func convertToSwiftData() -> StitchDocument {
203-
// let nodes = self.nodes.map { $0.convertToSwiftData() }
204-
// let doc = StitchDocument(nodes: nodes)
205-
// return doc
206-
// }
207-
// }
208-
//
209-
// extension CurrentNodeEntity.NodeEntity_Codable {
210-
// func convertToSwiftData() -> NodeEntity {
211-
// NodeEntity(id: self.nodeId,
212-
// position: self.position,
213-
// zIndex: self.zIndex,
214-
// customName: self.customName,
215-
// parentGroupNodeId: self.parentGroupNodeId,
216-
// patchNodeEntity: self.patchNodeEntity?.convertToSwiftData(),
217-
// // Nil for now
218-
// layerNodeEntity: nil)
219-
// }
220-
// }
221-
//
222-
// extension CurrentPatchNodeEntity.PatchNodeEntity_Codable {
223-
// func convertToSwiftData() -> PatchNodeEntity {
224-
// PatchNodeEntity(patch: self.patch,
225-
// userVisibleType: self.userVisibleType,
226-
// // Nil for now
227-
// splitterNode: nil)
228-
// }
229-
// }
230-
//
231-
// extension CurrentNodePortInputEntity.NodePortInputEntity_Codable {
232-
// func convertToSwiftData() -> NodePortInputEntity {
233-
// NodePortInputEntity(portId: self.portId,
234-
// label: self.label,
235-
// // TODO: blank for now
236-
// valueEntities: [],
237-
// connectedOutputEntity: nil)
238-
// }
239-
// }
188+
extension StitchComonentVersion {
189+
public static func getCodableType(from version: StitchSchemaVersion) -> any StitchVersionedCodable.Type {
190+
switch version {
191+
case ._V1, ._V2, ._V3, ._V4, ._V5, ._V6, ._V7, ._V8, ._V9, ._V10, ._V11, ._V12, ._V13, ._V14, ._V15, ._V16, ._V17, ._V18, ._V19, ._V20, ._V21, ._V22, ._V23:
192+
fatalError("No StitchComponent version expected before v24.")
193+
194+
case ._V24:
195+
return StitchComponent_V24.StitchComponent.self
196+
}
197+
}
198+
}

Sources/StitchSchemaKit/Util.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,5 @@ extension URL {
205205
}
206206
}
207207

208-
public typealias StitchPosition = CGSize
209208
public typealias ProjectId = UUID
210209
public typealias CommentBoxId = UUID

Sources/StitchSchemaKit/V1/NodePort/PortValue_V1.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public enum PortValue_V1: StitchSchemaVersionable {
6262
case networkRequestType(NetworkRequestType)
6363
case color(Color)
6464
case size(LayerSize)
65-
case position(StitchPosition) // TODO: use `CGPoint` instead of `CGSize`
65+
case position(CGSize) // TODO: use `CGPoint` instead of `CGSize`
6666
case point3D(Point3D)
6767
case point4D(Point4D)
6868
case pulse(TimeInterval) // TimeInterval = last time this input/output pulsed

Sources/StitchSchemaKit/V10/NodePort/PortValue_V10.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public enum PortValue_V10: StitchSchemaVersionable {
6868
case networkRequestType(NetworkRequestType)
6969
case color(Color)
7070
case size(LayerSize)
71-
case position(StitchPosition) // TODO: use `CGPoint` instead of `CGSize`
71+
case position(CGSize) // TODO: use `CGPoint` instead of `CGSize`
7272
case point3D(Point3D)
7373
case point4D(Point4D)
7474
case pulse(TimeInterval) // TimeInterval = last time this input/output pulsed

Sources/StitchSchemaKit/V11/NodePort/PortValue_V11.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public enum PortValue_V11: StitchSchemaVersionable {
6868
case networkRequestType(NetworkRequestType)
6969
case color(Color)
7070
case size(LayerSize)
71-
case position(StitchPosition) // TODO: use `CGPoint` instead of `CGSize`
71+
case position(CGSize) // TODO: use `CGPoint` instead of `CGSize`
7272
case point3D(Point3D)
7373
case point4D(Point4D)
7474
case pulse(TimeInterval) // TimeInterval = last time this input/output pulsed

Sources/StitchSchemaKit/V12/NodePort/PortValue_V12.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public enum PortValue_V12: StitchSchemaVersionable {
6868
case networkRequestType(NetworkRequestType)
6969
case color(Color)
7070
case size(LayerSize)
71-
case position(StitchPosition) // TODO: use `CGPoint` instead of `CGSize`
71+
case position(CGSize) // TODO: use `CGPoint` instead of `CGSize`
7272
case point3D(Point3D)
7373
case point4D(Point4D)
7474
case pulse(TimeInterval) // TimeInterval = last time this input/output pulsed

0 commit comments

Comments
 (0)