* Add mini editor example folder

* Adjust npm script

* Initialize the mini editor project

* Workable ts build

Add index.html

formatting

Inline html

Refine

* Add basic bridge APIs

* Refine bridge API: mount it to global

* Add platform target support

* Add comment

* Adjustment

* Refine file headers

* Implement basic web view of iOS

* Adjust toolbar UI

* No need to minify

* Refine toolbar UI

* Adjust native layer

* Add config

* Improve file headers

* Fix script

* Finish demo

* Fix return type

* Remove test targets and refine swift gen

* Rename: IEditor -> EditorBridge

* Remove empty line

* Remove launch json

* Use pattern to ignore launch json
This commit is contained in:
Daohan Chong 2021-07-27 16:58:09 +08:00 коммит произвёл GitHub
Родитель e5a1ea7d93
Коммит 9e569b0726
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
46 изменённых файлов: 6636 добавлений и 4 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -123,7 +123,7 @@ basic-types/dist
.npmrc
# debug config
.vscode/launch.json
**/.vscode/launch.json
src/basic-types

Просмотреть файл

Просмотреть файл

29
demo/mini-editor/apple/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,29 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
## Gcc Patch
/*.gcno
MiniEditor/Resources/bundle.html

Просмотреть файл

@ -0,0 +1,392 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
722DC0A126AFBB4B00945DC3 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 722DC0A026AFBB4B00945DC3 /* WebView.swift */; };
7232FDEC26AE9B30000C5376 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7232FDEB26AE9B30000C5376 /* AppDelegate.swift */; };
7232FDEE26AE9B30000C5376 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7232FDED26AE9B30000C5376 /* SceneDelegate.swift */; };
7232FDF026AE9B30000C5376 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7232FDEF26AE9B30000C5376 /* ViewController.swift */; };
7232FDF526AE9B34000C5376 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7232FDF426AE9B34000C5376 /* Assets.xcassets */; };
7232FDF826AE9B34000C5376 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7232FDF626AE9B34000C5376 /* LaunchScreen.storyboard */; };
7232FE2026AEB099000C5376 /* bundle.html in Resources */ = {isa = PBXBuildFile; fileRef = 7232FE1E26AEB099000C5376 /* bundle.html */; };
7232FE2326AEB0ED000C5376 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7232FE2226AEB0ED000C5376 /* WebKit.framework */; };
7232FE2526AEB5D6000C5376 /* Toolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7232FE2426AEB5D6000C5376 /* Toolbar.swift */; };
7232FE2726AEB831000C5376 /* ActionButtion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7232FE2626AEB831000C5376 /* ActionButtion.swift */; };
726EB1F926AFE5AB0008AF41 /* WebEditorTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 726EB1F726AFE5AB0008AF41 /* WebEditorTypes.swift */; };
726EB1FB26AFF36A0008AF41 /* EditorBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 726EB1FA26AFF36A0008AF41 /* EditorBridge.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
722DC0A026AFBB4B00945DC3 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
7232FDE826AE9B30000C5376 /* MiniEditor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MiniEditor.app; sourceTree = BUILT_PRODUCTS_DIR; };
7232FDEB26AE9B30000C5376 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7232FDED26AE9B30000C5376 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
7232FDEF26AE9B30000C5376 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
7232FDF426AE9B34000C5376 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7232FDF726AE9B34000C5376 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7232FDF926AE9B34000C5376 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7232FE1B26AEB047000C5376 /* MiniEditor.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MiniEditor.entitlements; sourceTree = "<group>"; };
7232FE1E26AEB099000C5376 /* bundle.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = bundle.html; sourceTree = "<group>"; };
7232FE2226AEB0ED000C5376 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/iOSSupport/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; };
7232FE2426AEB5D6000C5376 /* Toolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toolbar.swift; sourceTree = "<group>"; };
7232FE2626AEB831000C5376 /* ActionButtion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionButtion.swift; sourceTree = "<group>"; };
726EB1F726AFE5AB0008AF41 /* WebEditorTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebEditorTypes.swift; sourceTree = "<group>"; };
726EB1FA26AFF36A0008AF41 /* EditorBridge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorBridge.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
7232FDE526AE9B30000C5376 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
7232FE2326AEB0ED000C5376 /* WebKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
7232FDDF26AE9B30000C5376 = {
isa = PBXGroup;
children = (
7232FDEA26AE9B30000C5376 /* MiniEditor */,
7232FDE926AE9B30000C5376 /* Products */,
7232FE2126AEB0ED000C5376 /* Frameworks */,
);
sourceTree = "<group>";
};
7232FDE926AE9B30000C5376 /* Products */ = {
isa = PBXGroup;
children = (
7232FDE826AE9B30000C5376 /* MiniEditor.app */,
);
name = Products;
sourceTree = "<group>";
};
7232FDEA26AE9B30000C5376 /* MiniEditor */ = {
isa = PBXGroup;
children = (
726EB1F526AFE5AB0008AF41 /* Generated */,
7232FE1B26AEB047000C5376 /* MiniEditor.entitlements */,
7232FDEB26AE9B30000C5376 /* AppDelegate.swift */,
7232FDED26AE9B30000C5376 /* SceneDelegate.swift */,
7232FDEF26AE9B30000C5376 /* ViewController.swift */,
7232FDF426AE9B34000C5376 /* Assets.xcassets */,
7232FDF626AE9B34000C5376 /* LaunchScreen.storyboard */,
7232FDF926AE9B34000C5376 /* Info.plist */,
7232FE1C26AEB099000C5376 /* Resources */,
7232FE2426AEB5D6000C5376 /* Toolbar.swift */,
7232FE2626AEB831000C5376 /* ActionButtion.swift */,
722DC0A026AFBB4B00945DC3 /* WebView.swift */,
);
path = MiniEditor;
sourceTree = "<group>";
};
7232FE1C26AEB099000C5376 /* Resources */ = {
isa = PBXGroup;
children = (
7232FE1E26AEB099000C5376 /* bundle.html */,
);
path = Resources;
sourceTree = "<group>";
};
7232FE2126AEB0ED000C5376 /* Frameworks */ = {
isa = PBXGroup;
children = (
7232FE2226AEB0ED000C5376 /* WebKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
726EB1F526AFE5AB0008AF41 /* Generated */ = {
isa = PBXGroup;
children = (
726EB1FA26AFF36A0008AF41 /* EditorBridge.swift */,
726EB1F726AFE5AB0008AF41 /* WebEditorTypes.swift */,
);
path = Generated;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
7232FDE726AE9B30000C5376 /* MiniEditor */ = {
isa = PBXNativeTarget;
buildConfigurationList = 7232FE1226AE9B34000C5376 /* Build configuration list for PBXNativeTarget "MiniEditor" */;
buildPhases = (
7232FDE426AE9B30000C5376 /* Sources */,
7232FDE526AE9B30000C5376 /* Frameworks */,
7232FDE626AE9B30000C5376 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = MiniEditor;
productName = MiniEditor;
productReference = 7232FDE826AE9B30000C5376 /* MiniEditor.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
7232FDE026AE9B30000C5376 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1250;
TargetAttributes = {
7232FDE726AE9B30000C5376 = {
CreatedOnToolsVersion = 12.5.1;
};
};
};
buildConfigurationList = 7232FDE326AE9B30000C5376 /* Build configuration list for PBXProject "MiniEditor" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 7232FDDF26AE9B30000C5376;
productRefGroup = 7232FDE926AE9B30000C5376 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
7232FDE726AE9B30000C5376 /* MiniEditor */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
7232FDE626AE9B30000C5376 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7232FE2026AEB099000C5376 /* bundle.html in Resources */,
7232FDF826AE9B34000C5376 /* LaunchScreen.storyboard in Resources */,
7232FDF526AE9B34000C5376 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
7232FDE426AE9B30000C5376 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7232FDF026AE9B30000C5376 /* ViewController.swift in Sources */,
726EB1FB26AFF36A0008AF41 /* EditorBridge.swift in Sources */,
726EB1F926AFE5AB0008AF41 /* WebEditorTypes.swift in Sources */,
7232FDEC26AE9B30000C5376 /* AppDelegate.swift in Sources */,
7232FDEE26AE9B30000C5376 /* SceneDelegate.swift in Sources */,
722DC0A126AFBB4B00945DC3 /* WebView.swift in Sources */,
7232FE2726AEB831000C5376 /* ActionButtion.swift in Sources */,
7232FE2526AEB5D6000C5376 /* Toolbar.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
7232FDF626AE9B34000C5376 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
7232FDF726AE9B34000C5376 /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
7232FE1026AE9B34000C5376 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
7232FE1126AE9B34000C5376 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
7232FE1326AE9B34000C5376 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = MiniEditor/MiniEditor.entitlements;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = MiniEditor/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.ts-codegen.demo.MiniEditor.MiniEditor";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,6";
};
name = Debug;
};
7232FE1426AE9B34000C5376 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = MiniEditor/MiniEditor.entitlements;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = MiniEditor/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.ts-codegen.demo.MiniEditor.MiniEditor";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,6";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
7232FDE326AE9B30000C5376 /* Build configuration list for PBXProject "MiniEditor" */ = {
isa = XCConfigurationList;
buildConfigurations = (
7232FE1026AE9B34000C5376 /* Debug */,
7232FE1126AE9B34000C5376 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7232FE1226AE9B34000C5376 /* Build configuration list for PBXNativeTarget "MiniEditor" */ = {
isa = XCConfigurationList;
buildConfigurations = (
7232FE1326AE9B34000C5376 /* Debug */,
7232FE1426AE9B34000C5376 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 7232FDE026AE9B30000C5376 /* Project object */;
}

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

Просмотреть файл

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7232FDE726AE9B30000C5376"
BuildableName = "MiniEditor.app"
BlueprintName = "MiniEditor"
ReferencedContainer = "container:MiniEditor.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7232FDFD26AE9B34000C5376"
BuildableName = "MiniEditorTests.xctest"
BlueprintName = "MiniEditorTests"
ReferencedContainer = "container:MiniEditor.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7232FE0826AE9B34000C5376"
BuildableName = "MiniEditorUITests.xctest"
BlueprintName = "MiniEditorUITests"
ReferencedContainer = "container:MiniEditor.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7232FDE726AE9B30000C5376"
BuildableName = "MiniEditor.app"
BlueprintName = "MiniEditor"
ReferencedContainer = "container:MiniEditor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7232FDE726AE9B30000C5376"
BuildableName = "MiniEditor.app"
BlueprintName = "MiniEditor"
ReferencedContainer = "container:MiniEditor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

Просмотреть файл

@ -0,0 +1,35 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
import UIKit
class ActionButton: UIButton {
var onTap: (() -> Void)?
init(systemName: String, onTap: @escaping () -> Void) {
super.init(frame: .zero)
translatesAutoresizingMaskIntoConstraints = false
self.onTap = onTap
setImage(UIImage(systemName: systemName), for: .normal)
addTarget(self, action: #selector(buttonDidTap), for: .touchUpInside)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
private extension ActionButton {
@objc func buttonDidTap() {
onTap?()
}
}

Просмотреть файл

@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}

Просмотреть файл

@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Просмотреть файл

@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Просмотреть файл

@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

Просмотреть файл

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>

Просмотреть файл

@ -0,0 +1,112 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// swiftformat:disable redundantRawValues
// Don't modify this file manually, it's auto generated.
import WebKit
public class EditorBridge {
weak var webView: WKWebView?
private let jsonEncoder = JSONEncoder()
private let jsonDecoder = JSONDecoder()
init(webView: WKWebView) {
self.webView = webView
}
public func toggleBold(completion: ((Result<Void, Error>) -> Void)? = nil) {
let javaScriptString = "editor.toggleBold" + "(" + ")"
print("[ts-codegen] evaluating: \(javaScriptString)")
webView?.evaluateJavaScript(javaScriptString) { evaluationResult, error in
guard let completion = completion else { return }
if let error = error {
completion(.failure(error))
return
}
completion(.success(()))
}
}
public func toggleItalic(completion: ((Result<Void, Error>) -> Void)? = nil) {
let javaScriptString = "editor.toggleItalic" + "(" + ")"
print("[ts-codegen] evaluating: \(javaScriptString)")
webView?.evaluateJavaScript(javaScriptString) { evaluationResult, error in
guard let completion = completion else { return }
if let error = error {
completion(.failure(error))
return
}
completion(.success(()))
}
}
public func toggleUnderline(completion: ((Result<Void, Error>) -> Void)? = nil) {
let javaScriptString = "editor.toggleUnderline" + "(" + ")"
print("[ts-codegen] evaluating: \(javaScriptString)")
webView?.evaluateJavaScript(javaScriptString) { evaluationResult, error in
guard let completion = completion else { return }
if let error = error {
completion(.failure(error))
return
}
completion(.success(()))
}
}
public func clear(completion: ((Result<Void, Error>) -> Void)? = nil) {
let javaScriptString = "editor.clear" + "(" + ")"
print("[ts-codegen] evaluating: \(javaScriptString)")
webView?.evaluateJavaScript(javaScriptString) { evaluationResult, error in
guard let completion = completion else { return }
if let error = error {
completion(.failure(error))
return
}
completion(.success(()))
}
}
public func insertContent(content: String, newLine: Bool?, completion: @escaping (Result<InsertContentResult, Error>) -> Void) {
struct Args: Encodable {
let content: String
let newLine: Bool?
}
let args = Args(
content: content,
newLine: newLine
)
let argsString = String(data: try! jsonEncoder.encode(args), encoding: .utf8)!
let javaScriptString = "editor.insertContent" + "(" + "\(argsString)" + ")"
print("[ts-codegen] evaluating: \(javaScriptString)")
webView?.evaluateJavaScript(javaScriptString) { [unowned self]evaluationResult, error in
if let error = error {
completion(.failure(error))
return
}
let data = try! JSONSerialization.data(withJSONObject: evaluationResult!)
let result = try! self.jsonDecoder.decode(InsertContentResult.self, from: data)
completion(.success(result))
}
}
}
public struct InsertContentResult: Codable {
public var html: String
public init(html: String) {
self.html = html
}
}

Просмотреть файл

@ -0,0 +1,8 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// swiftformat:disable redundantRawValues
// Don't modify this file manually, it's auto generated.
import UIKit

Просмотреть файл

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

Просмотреть файл

Просмотреть файл

@ -0,0 +1,49 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}

Просмотреть файл

@ -0,0 +1,86 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
import UIKit
protocol ToolbarDelegate: AnyObject {
func toolbarDidToggleBold()
func toolbarDidToggleItalic()
func toolbarDidToggleUnderline()
func toolbarDidTapInsertContent()
}
class Toolbar: UIView {
weak var delegate: ToolbarDelegate?
private lazy var stackViewContainer: UIStackView = {
let stackViewContainer = UIStackView(arrangedSubviews: [
boldButton,
italicButton,
underlineButton,
insertContentButton,
])
stackViewContainer.translatesAutoresizingMaskIntoConstraints = false
stackViewContainer.spacing = 5.0
stackViewContainer.distribution = .fillEqually
return stackViewContainer
}()
private lazy var boldButton = buildButton(systemImage: "bold") { [weak self] in
self?.delegate?.toolbarDidToggleBold()
}
private lazy var italicButton = buildButton(systemImage: "italic") { [weak self] in
self?.delegate?.toolbarDidToggleItalic()
}
private lazy var underlineButton = buildButton(systemImage: "underline") { [weak self] in
self?.delegate?.toolbarDidToggleBold()
}
private lazy var insertContentButton = buildButton(systemImage: "rectangle.and.pencil.and.ellipsis") { [weak self] in
self?.delegate?.toolbarDidTapInsertContent()
}
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(stackViewContainer)
NSLayoutConstraint.activate([
stackViewContainer.topAnchor.constraint(equalTo: topAnchor),
stackViewContainer.leadingAnchor.constraint(equalTo: leadingAnchor),
stackViewContainer.trailingAnchor.constraint(equalTo: trailingAnchor),
stackViewContainer.bottomAnchor.constraint(equalTo: bottomAnchor),
])
stackViewContainer.backgroundColor = .secondarySystemBackground
configurateFrame()
setNeedsLayout()
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
configurateFrame()
}
}
private extension Toolbar {
func buildButton(systemImage: String, onTap: @escaping () -> Void) -> UIButton {
ActionButton(systemName: systemImage, onTap: onTap)
}
func configurateFrame() {
frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50)
}
}

Просмотреть файл

@ -0,0 +1,92 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
import UIKit
import WebKit
class ViewController: UIViewController {
private lazy var webView: WKWebView = {
let webView = WebView()
webView.translatesAutoresizingMaskIntoConstraints = false
let toolbar = Toolbar()
toolbar.delegate = self
webView.toolbar = toolbar
return webView
}()
private lazy var editorBridge = EditorBridge(webView: webView)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .systemBackground
view.addSubview(webView)
NSLayoutConstraint.activate([
webView.topAnchor.constraint(equalTo: view.topAnchor),
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
loadJavaScriptBundle()
}
}
extension ViewController: ToolbarDelegate {
func toolbarDidToggleBold() {
editorBridge.toggleBold { [unowned self] result in
self.handleVoidResult(result)
}
}
func toolbarDidToggleItalic() {
editorBridge.toggleItalic { [unowned self] result in
self.handleVoidResult(result)
}
}
func toolbarDidToggleUnderline() {
editorBridge.toggleUnderline { [unowned self] result in
self.handleVoidResult(result)
}
}
func toolbarDidTapInsertContent() {
editorBridge.insertContent(
content: "did tap insert content",
newLine: true
) { result in
switch result {
case .success(let contentString):
print("[ts-codegen] contentString after insertContent(): \(contentString)")
case .failure(let error):
assertionFailure("\(error)")
}
}
}
}
private extension ViewController {
func loadJavaScriptBundle() {
let bundleURL = Bundle.main.url(forResource: "bundle", withExtension: "html")!
let javaScriptContent = try! String(contentsOf: bundleURL, encoding: .utf8)
webView.loadHTMLString(javaScriptContent, baseURL: nil)
}
func handleVoidResult(_ result: Result<Void, Error>) {
switch result {
case .success:
break
case .failure(let error):
assertionFailure("\(error)")
}
}
}

Просмотреть файл

@ -0,0 +1,14 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
import UIKit
import WebKit
class WebView: WKWebView {
var toolbar: Toolbar?
override var inputAccessoryView: UIView? {
toolbar
}
}

Просмотреть файл

@ -0,0 +1,38 @@
{{#custom}}
{{#documentationLines}}
///{{{.}}}
{{/documentationLines}}
public struct {{typeName}}: Codable {
{{#members}}
{{#documentationLines}}
///{{{.}}}
{{/documentationLines}}
public var {{name}}: {{type}}
{{/members}}
{{#staticMembers}}
{{#documentationLines}}
///{{{.}}}
{{/documentationLines}}
private var {{name}}: {{type}} = {{{value}}}
{{/staticMembers}}
public init({{#members}}{{name}}: {{type}}{{^last}}, {{/last}}{{/members}}) {
{{#members}}
self.{{name}} = {{name}}
{{/members}}
}
}
{{/custom}}
{{#enum}}
{{#documentationLines}}
///{{{.}}}
{{/documentationLines}}
public enum {{typeName}}: {{valueType}}, Codable {
{{#members}}
{{#documentationLines}}
///{{{.}}}
{{/documentationLines}}
case {{key}} = {{{value}}}
{{/members}}
}
{{/enum}}

Просмотреть файл

@ -0,0 +1,67 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// swiftformat:disable redundantRawValues
// Don't modify this file manually, it's auto generated.
import WebKit
public class {{moduleName}} {
{{#customTags.privateDispatcher}}private {{/customTags.privateDispatcher}}weak var webView: WKWebView?
private let jsonEncoder = JSONEncoder()
private let jsonDecoder = JSONDecoder()
init(webView: WKWebView) {
self.webView = webView
}
{{#methods}}
{{#documentationLines}}
///{{{.}}}
{{/documentationLines}}
public func {{methodName}}({{parametersDeclaration}}{{#parametersDeclaration.length}}, {{/parametersDeclaration.length}}completion: {{#returnType}}@escaping (Result<{{returnType}}, Error>) -> Void{{/returnType}}{{^returnType}}((Result<Void, Error>) -> Void)? = nil{{/returnType}}) {
{{#parameters.length}}
struct Args: Encodable {
{{#parameters}}
let {{name}}: {{type}}
{{/parameters}}
}
{{/parameters.length}}
{{#parameters.length}}
let args = Args(
{{#parameters}}
{{name}}: {{name}}{{^last}},{{/last}}
{{/parameters}}
)
let argsString = String(data: try! jsonEncoder.encode(args), encoding: .utf8)!
{{/parameters.length}}
let javaScriptString = "{{customTags.invokePath}}.{{methodName}}" + "(" {{#parameters.length}}+ "\(argsString)"{{/parameters.length}} + ")"
print("[ts-codegen] evaluating: \(javaScriptString)")
webView?.evaluateJavaScript(javaScriptString) { {{#returnType}}[unowned self]{{/returnType}}evaluationResult, error in
{{^returnType}}
guard let completion = completion else { return }
{{/returnType}}
if let error = error {
completion(.failure(error))
return
}
{{#returnType}}
let data = try! JSONSerialization.data(withJSONObject: evaluationResult!)
let result = try! self.jsonDecoder.decode({{returnType}}.self, from: data)
completion(.success(result))
{{/returnType}}
{{^returnType}}
completion(.success(()))
{{/returnType}}
}
}
{{/methods}}
}
{{#associatedTypes}}
{{> swift-named-type}}
{{/associatedTypes}}

Просмотреть файл

@ -0,0 +1,27 @@
{
"parsing": {
"source": {
"api": ["src/editor/IEditor.ts"]
},
"predefinedTypes": [
"CodeGen_Int"
],
"defaultCustomTags": {},
"dropInterfaceIPrefix": true
},
"rendering": {
"swift": {
"templates": {
"api": "code-templates/swift.mustache"
},
"outputDirectory": {
"api": "../apple/MiniEditor/generated"
},
"namedTypesTemplatePath": "../../../example-templates/swift-named-types.mustache",
"namedTypesOutputPath": "../apple/MiniEditor/Generated/WebEditorTypes.swift",
"typeNameMap": {
"CodeGen_Int": "Int"
}
}
}
}

5084
demo/mini-editor/web/package-lock.json сгенерированный Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,27 @@
{
"name": "mini-editor-web",
"version": "0.0.1",
"description": "An end-to-end example of ts-codegen",
"main": "src/main.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:web": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack --env target='web'",
"build:apple": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack --env target='apple'",
"serve:web": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack serve --env target='web'"
},
"author": "",
"license": "MIT",
"devDependencies": {
"cross-env": "^7.0.3",
"html-inline-css-webpack-plugin": "^1.11.1",
"html-inline-script-webpack-plugin": "^2.0.2",
"html-webpack-plugin": "^5.3.2",
"mini-css-extract-plugin": "^2.1.0",
"ts-loader": "^9.2.4",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5",
"webpack": "^5.46.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
}
}

Просмотреть файл

@ -0,0 +1,34 @@
import { IEditor, IInsertContentResult } from "./IEditor";
export class Editor implements IEditor {
constructor(private contentEditableDiv: HTMLDivElement) { }
toggleBold(): void {
document.execCommand('bold');
}
toggleItalic(): void {
document.execCommand('italic');
}
toggleUnderline(): void {
document.execCommand('underline');
}
focus(): void {
this.contentEditableDiv.focus();
}
clear(): void {
this.contentEditableDiv.innerHTML = '';
this.focus();
}
insertContent({ content, newLine }: { content: string; newLine?: boolean | undefined; }): IInsertContentResult {
const contentBeingInserted = newLine ? `${content}\n` : content;
document.execCommand('insertHTML', false, contentBeingInserted);
return { html: this.contentEditableDiv.innerHTML };
}
}

Просмотреть файл

@ -0,0 +1,19 @@
/**
* @shouldExport true
* @invokePath editor
* @overrideModuleName EditorBridge
*/
export interface IEditor {
toggleBold(): void;
toggleItalic(): void;
toggleUnderline(): void;
clear(): void;
insertContent({ content, newLine }: { content: string; newLine?: boolean }): IInsertContentResult;
}
export interface IInsertContentResult {
html: string;
}

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mini Editor</title>
</head>
<body>
<div id="mini-editor" contenteditable="true">
Hello, I'm a mini editor (⁎⁍̴̛ᴗ⁍̴̛⁎)
</div>
<script src="bundle.js"></script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,14 @@
import { Editor } from "./editor/Editor";
import { onReady } from "./utils/onReady";
onReady(() => {
const editor = new Editor(document.getElementById("mini-editor") as HTMLDivElement);
console.log('Editor is ready:', editor);
// Mount `editor` into global scope
window.editor = editor;
requestAnimationFrame(() => {
editor.focus();
});
});

7
demo/mini-editor/web/src/types/types.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,7 @@
import { IEditor } from '../editor/IEditor';
declare global {
interface Window {
editor: IEditor;
}
}

Просмотреть файл

@ -0,0 +1,7 @@
export function onReady(cb: () => void): void {
if (document.readyState !== 'loading') {
setTimeout(cb, 0);
} else {
document.addEventListener('DOMContentLoaded', cb);
}
}

Просмотреть файл

@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"esModuleInterop": true
}
}

Просмотреть файл

@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.json",
"include": [
"src/**/*.ts"
],
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"es5",
"es6",
"es2015.promise",
"es2016"
],
"typeRoots": [
"src/types"
]
}
}

Просмотреть файл

@ -0,0 +1,85 @@
// TypeScript based configuration for webpack.
// Reference: https://webpack.js.org/configuration/configuration-languages/#typescript
import path from 'path';
import * as webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import HTMLInlineCSSWebpackPlugin from 'html-inline-css-webpack-plugin';
import HtmlInlineScriptPlugin from 'html-inline-script-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
const webDistPath = path.resolve(__dirname, 'dist');
const sourcePath = path.resolve(__dirname, 'src');
const appleDistPath = path.resolve(__dirname, '..', 'apple/MiniEditor/Resources');
enum SupportedTarget {
web = 'web',
apple = 'apple',
}
interface WebpackEnvironment {
target: SupportedTarget;
port?: number;
}
function buildConfig(env: WebpackEnvironment): webpack.Configuration | webpack.WebpackOptionsNormalized {
const isProductionBuild = process.env.NODE_ENV === 'production';
const distPath = env.target == SupportedTarget.web ? webDistPath : appleDistPath;
return {
mode: isProductionBuild ? 'production' : 'development',
entry: `${sourcePath}/main.ts`,
devServer: {
contentBase: distPath,
compress: true,
port: env.port ?? 9000,
},
output: {
path: distPath,
filename: 'bundle.js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
include: [
sourcePath,
],
use: [
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.json',
compilerOptions: {
sourceMap: !isProductionBuild,
},
},
},
],
}
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
// Note: For mobile platforms, we need to inline all JavaScript
// and CSS resources into a single file for simplicity.
new HtmlWebpackPlugin({
template: `${sourcePath}/index.html`,
filename: './bundle.html',
inlineSource: '.(js|css)$',
}),
new HTMLInlineCSSWebpackPlugin(),
new HtmlInlineScriptPlugin(),
]
};
}
export default (env) => buildConfig(env);;

Просмотреть файл

@ -1,5 +1,5 @@
//
// Copyright 2013-2018 Microsoft Inc.
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// swiftformat:disable redundantRawValues

Просмотреть файл

@ -1,5 +1,5 @@
//
// Copyright 2013-2018 Microsoft Inc.
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// swiftformat:disable redundantRawValues

Просмотреть файл

@ -6,7 +6,8 @@
"build": "tsc",
"clean": "rm -rf dist",
"debug": "ts-node ./src/cli/index",
"start:example": "npm run debug -- --config demo/config.json",
"start:example:basic": "npm run debug -- --config demo/basic/config.json",
"start:example:mini-editor": "npm run debug -- --config demo/mini-editor/web/config.json",
"test": "mocha -r ts-node/register test/**/*.ts",
"lint": "eslint ./src --ext .js,.ts",
"prettier:write": "prettier --write \"src/**/*.ts\"",