From ee333e3b0c29bb3a4ff17e53ad4ae98ce7e91a80 Mon Sep 17 00:00:00 2001
From: Jane Chu <7559015+janechu@users.noreply.github.com>
Date: Fri, 15 May 2020 10:39:37 -0700
Subject: [PATCH] chore: add basic example wiring for both web components and
react (#3140)
---
sites/fast-tooling-examples/CONTRIBUTORS.md | 20 +++++++
.../app/example-react-1.ts | 4 ++
.../app/example-web-component-1.ts | 4 ++
.../app/examples/react-1/example.tsx | 24 +++++++++
.../app/examples/react-1/index.html | 28 ++++++++++
.../app/examples/react-1/index.tsx | 8 +++
.../app/examples/web-component-1/index.html | 28 ++++++++++
.../app/examples/web-component-1/index.ts | 17 ++++++
sites/fast-tooling-examples/app/index.html | 52 ++++++++++++++++++-
sites/fast-tooling-examples/app/index.ts | 43 +++++++++++++--
sites/fast-tooling-examples/app/registry.ts | 11 ++++
sites/fast-tooling-examples/app/style.css | 31 +++++++++--
sites/fast-tooling-examples/package.json | 4 +-
sites/fast-tooling-examples/webpack.config.js | 24 +++++++++
yarn.lock | 27 ++++++++++
15 files changed, 316 insertions(+), 9 deletions(-)
create mode 100644 sites/fast-tooling-examples/CONTRIBUTORS.md
create mode 100644 sites/fast-tooling-examples/app/example-react-1.ts
create mode 100644 sites/fast-tooling-examples/app/example-web-component-1.ts
create mode 100644 sites/fast-tooling-examples/app/examples/react-1/example.tsx
create mode 100644 sites/fast-tooling-examples/app/examples/react-1/index.html
create mode 100644 sites/fast-tooling-examples/app/examples/react-1/index.tsx
create mode 100644 sites/fast-tooling-examples/app/examples/web-component-1/index.html
create mode 100644 sites/fast-tooling-examples/app/examples/web-component-1/index.ts
create mode 100644 sites/fast-tooling-examples/app/registry.ts
diff --git a/sites/fast-tooling-examples/CONTRIBUTORS.md b/sites/fast-tooling-examples/CONTRIBUTORS.md
new file mode 100644
index 00000000000..749bc73a155
--- /dev/null
+++ b/sites/fast-tooling-examples/CONTRIBUTORS.md
@@ -0,0 +1,20 @@
+# Adding a new example
+
+When adding a new example the following steps should be taken:
+- Add a link in the `app/index.html` to the example in the appropriate category.
+- Add a TypeScript file named with the corresponding example numbering and category, `example-{category}-{number}.ts`, for example `example-react-2.ts` the contents of which should include in it an `id`, in this case `react-2`, and a `text` property that will go above the example.
+
+Example:
+```typescript
+ export default {
+ id: "react-2",
+ text: "An example editor using the Viewer, Form and Navigation components.",
+};
+```
+
+- Add this new example to the `registry.ts` file by following the syntax there.
+- Add a folder in the examples file with your new example.
+- Add to the `webpack.config.js` file a new `entry` in the above example with camelCase naming corresponding to the name of the example file, taking the example file name `example-react-2` above, it would be `exampleReact2` and point it to your new `index.ts`/`index.tsx` file in your example folder.
+- Add to the `webpack.config.js` file a new instance of `HtmlWebpackPlugin` which points to your new template. Be sure to filter out the main js file and all other example js files so that they only include your own, use other template files as reference.
+
+Note: Naming conventions must be strictly adhered to for templating to strip out irrelevant script files.
diff --git a/sites/fast-tooling-examples/app/example-react-1.ts b/sites/fast-tooling-examples/app/example-react-1.ts
new file mode 100644
index 00000000000..de2cae2d4e1
--- /dev/null
+++ b/sites/fast-tooling-examples/app/example-react-1.ts
@@ -0,0 +1,4 @@
+export default {
+ id: "react-1",
+ text: "React 1",
+};
diff --git a/sites/fast-tooling-examples/app/example-web-component-1.ts b/sites/fast-tooling-examples/app/example-web-component-1.ts
new file mode 100644
index 00000000000..f3f546262df
--- /dev/null
+++ b/sites/fast-tooling-examples/app/example-web-component-1.ts
@@ -0,0 +1,4 @@
+export default {
+ id: "web-component-1",
+ text: "Web Component 1",
+};
diff --git a/sites/fast-tooling-examples/app/examples/react-1/example.tsx b/sites/fast-tooling-examples/app/examples/react-1/example.tsx
new file mode 100644
index 00000000000..d987c15ce5a
--- /dev/null
+++ b/sites/fast-tooling-examples/app/examples/react-1/example.tsx
@@ -0,0 +1,24 @@
+import React from "react";
+import FASTMessageSystemWorker from "@microsoft/fast-tooling/dist/message-system.min.js";
+import { MessageSystem } from "@microsoft/fast-tooling";
+
+const fastMessageSystemWorker = new FASTMessageSystemWorker();
+let fastMessageSystem: MessageSystem;
+
+class Example extends React.Component<{}, {}> {
+ constructor(props) {
+ super(props);
+
+ if ((window as any).Worker) {
+ fastMessageSystem = new MessageSystem({
+ webWorker: fastMessageSystemWorker,
+ });
+ }
+ }
+
+ render() {
+ return React Example 1;
+ }
+}
+
+export default Example;
diff --git a/sites/fast-tooling-examples/app/examples/react-1/index.html b/sites/fast-tooling-examples/app/examples/react-1/index.html
new file mode 100644
index 00000000000..bb935557575
--- /dev/null
+++ b/sites/fast-tooling-examples/app/examples/react-1/index.html
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+ <%= htmlWebpackPlugin.tags.headTags %>
+ <%= htmlWebpackPlugin.options.title %>
+
+
+
+
+ <%= htmlWebpackPlugin
+ .tags
+ .bodyTags
+ .filter(
+ (tag) =>
+ !tag.attributes.src.includes('main')
+ && (
+ !tag.attributes.src.includes('example')
+ || tag.attributes.src.includes('exampleReact1')
+ )
+ )
+ .join('')
+ %>
+
+
+
\ No newline at end of file
diff --git a/sites/fast-tooling-examples/app/examples/react-1/index.tsx b/sites/fast-tooling-examples/app/examples/react-1/index.tsx
new file mode 100644
index 00000000000..afec0cd1307
--- /dev/null
+++ b/sites/fast-tooling-examples/app/examples/react-1/index.tsx
@@ -0,0 +1,8 @@
+import React from "react";
+import ReactDOM from "react-dom";
+import Example from "./example";
+
+/**
+ * Primary render function for app. Called on store updates
+ */
+ReactDOM.render(, document.getElementById("root"));
diff --git a/sites/fast-tooling-examples/app/examples/web-component-1/index.html b/sites/fast-tooling-examples/app/examples/web-component-1/index.html
new file mode 100644
index 00000000000..1e515c114c1
--- /dev/null
+++ b/sites/fast-tooling-examples/app/examples/web-component-1/index.html
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+ <%= htmlWebpackPlugin.tags.headTags %>
+ <%= htmlWebpackPlugin.options.title %>
+
+
+
+
+ <%= htmlWebpackPlugin
+ .tags
+ .bodyTags
+ .filter(
+ (tag) =>
+ !tag.attributes.src.includes('main')
+ && (
+ !tag.attributes.src.includes('example')
+ || tag.attributes.src.includes('exampleWebComponent1')
+ )
+ )
+ .join('')
+ %>
+
+
+
\ No newline at end of file
diff --git a/sites/fast-tooling-examples/app/examples/web-component-1/index.ts b/sites/fast-tooling-examples/app/examples/web-component-1/index.ts
new file mode 100644
index 00000000000..fa11b3a3784
--- /dev/null
+++ b/sites/fast-tooling-examples/app/examples/web-component-1/index.ts
@@ -0,0 +1,17 @@
+import FASTMessageSystemWorker from "@microsoft/fast-tooling/dist/message-system.min.js";
+import { MessageSystem } from "@microsoft/fast-tooling";
+
+const fastMessageSystemWorker = new FASTMessageSystemWorker();
+let fastMessageSystem: MessageSystem;
+
+if ((window as any).Worker) {
+ fastMessageSystem = new MessageSystem({
+ webWorker: fastMessageSystemWorker,
+ });
+}
+
+const root = document.getElementById("root");
+
+if (root !== null) {
+ root.innerHTML = "Web Components Example 1";
+}
diff --git a/sites/fast-tooling-examples/app/index.html b/sites/fast-tooling-examples/app/index.html
index 352ecfc9b1b..0d70a5488e7 100644
--- a/sites/fast-tooling-examples/app/index.html
+++ b/sites/fast-tooling-examples/app/index.html
@@ -4,6 +4,7 @@
+ <%= htmlWebpackPlugin.tags.headTags %>
<%= htmlWebpackPlugin.options.title %>
@@ -40,19 +41,68 @@
Tooling
+
+ -
+
+ Message System
+
+
+
- Placeholder
+
+
+ Tooling Examples
+
+
+
+ Showcasing common use cases for @microsoft/fast-tooling
and @microsoft/fast-tooling-react
+
+
+ The examples in this site serve to better illustrate:
+
+
+ -
+ How to use the message system
+
+ -
+ How to use the available React components
+
+
+
+ Additionally each example is encapsulated in its own folder which can be copied as used as a starting point.
+
+
+
+ <%= htmlWebpackPlugin
+ .tags
+ .bodyTags
+ .filter((tag) => !tag.attributes.src.includes('example'))
+ .join('')
+ %>