Skip to content

Commit 9ced6f1

Browse files
committed
switch name of cms-editor.html to iframe.html
This general iframe version of CLUE is used for snapshots and for the CMS. It could also be used for embedding CLUE inside of the Activity Player. Also: - Remove unused cms params located in url-params - add "allow serial" to iframe to remove console warning
1 parent d6c7a63 commit 9ced6f1

11 files changed

+46
-47
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ To enable per component debugging set the "debug" localstorage key with one or m
110110

111111
- `bookmarks` this will show a tiny text status above the bookmark indicating which users have bookmarked this document. It will also print information about the document bookmarks each time a bookmark is toggled.
112112
- `canvas` this will show the document key over the canvas, useful for looking up documents in Firebase
113-
- `cms` this will print info to the console as changes are made to authored content via the CMS
113+
- `iframe` this will print info to the console as document changes are sent from the iframe'd CLUE to the parent frame. This iframe'd CLUE is used by the CMS.
114114
- `docList` - this will print a table of information about a list of documents
115115
- `document` this will add the active document as `window.currentDocument`, you can use MST's hidden toJSON() like `currentDocument.toJSON()` to views its content.
116116
- `drop` console log the dataTransfer object from drop events on the document.

Diff for: cms/src/cms-url-params.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export interface QueryParams {
1717
curriculumBranch?: string;
1818
// work with a local checkout of the curriculum instead of github
1919
localCMSBackend?: boolean;
20-
// change the location of the cms-editor.html used by iframe widget to edit
20+
// change the location of the iframe.html used by the iframe widget to edit
2121
// CLUE documents.
22-
cmsEditorBase?: string;
22+
iframeBase?: string;
2323
}
2424

2525
export const processUrlParams = (): QueryParams => {

Diff for: cms/src/iframe-control.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import { Map } from "immutable";
33
import { CmsWidgetControlProps } from "decap-cms-core";
44

55
import { urlParams } from "./cms-url-params";
6-
import { DEBUG_CMS } from "../../src/lib/debug";
6+
import { DEBUG_IFRAME } from "../../src/lib/debug";
77
import { defaultCurriculumBranch } from "./cms-constants";
88

99
import "./iframe-control.scss";
1010

1111
(window as any).DISABLE_FIREBASE_SYNC = true;
1212

13-
const cmsEditorBase = urlParams.cmsEditorBase ?? ".";
13+
const iframeBase = urlParams.iframeBase ?? ".";
1414
// the URL is relative to the current url of the CMS
15-
// If the cmsEditorBase is an absolute url then the current url will be ignored
16-
const cmsEditorBaseURL = new URL(cmsEditorBase, window.location.href);
17-
const validOrigin = cmsEditorBaseURL.origin;
15+
// If the iframeBase is an absolute url then the current url will be ignored
16+
const iframeBaseURL = new URL(iframeBase, window.location.href);
17+
const validOrigin = iframeBaseURL.origin;
1818

1919
interface IState {
2020
initialValue?: string;
@@ -28,7 +28,7 @@ export class IframeControl extends React.Component<CmsWidgetControlProps, IState
2828
}
2929

3030
componentDidMount = () => {
31-
if (DEBUG_CMS) {
31+
if (DEBUG_IFRAME) {
3232
// eslint-disable-next-line no-console
3333
console.log("DEBUG: CMS ClueControl initial content value is: ", this.state.initialValue);
3434
}
@@ -66,13 +66,13 @@ export class IframeControl extends React.Component<CmsWidgetControlProps, IState
6666

6767
render() {
6868
const curriculumBranch = urlParams.curriculumBranch ?? defaultCurriculumBranch;
69-
const iframeBaseUrl = `${cmsEditorBase}/cms-editor.html?curriculumBranch=${curriculumBranch}`;
69+
const iframeBaseUrl = `${iframeBase}/iframe.html?curriculumBranch=${curriculumBranch}`;
7070
const iframeUrl = urlParams.unit
7171
? `${iframeBaseUrl}&unit=${urlParams.unit}`
7272
: iframeBaseUrl;
7373
return (
7474
<div className="iframe-control custom-widget">
75-
<iframe id="editor" src={iframeUrl} allow="clipboard-read; clipboard-write"
75+
<iframe id="editor" src={iframeUrl} allow="clipboard-read; clipboard-write; serial"
7676
onLoad={this.sendInitialValueToEditor.bind(this)}>
7777
</iframe>
7878
</div>

Diff for: docs/cms.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CLUE includes a CMS which can be accessed at `/admin.html` in a production build
66

77
- **`curriculumBranch`** By default the CMS edits the `author` branch. You can change the branch by passing a different branch name to this parameter. The CMS will not create this branch for you. You'll need to create it yourself.
88
- **`unit`** By default the CMS displays all of the units at the same time. It is better to work with a single unit at a time by using the `unit` param. It should be passed the unit code. This limits what is displayed in the CMS and it also configures the media library to show the images from that unit.
9-
- **`cmsEditorBase`** By default the CMS will use an iframe pointed at `./cms-editor.html` to edit the CLUE documents. You can use this param to replace `.` with something else. This is useful for local testing (see below)
9+
- **`iframeBase`** By default the CMS will use an iframe pointed at `./iframe.html` to edit the CLUE documents. You can use this param to replace `.` with something else. This is useful for local testing (see below)
1010
- **`localCMSBackend`** By default the CMS works with the `github` backend. This means even when doing local CLUE development the CMS will update the `clue-curriculum` repository directly. If you add the `localCMSBackend` parameter the CMS will attempt to work with a local git proxy running at localhost:8081. You can start this proxy with:
1111

1212
`cd ../clue-curriculum; npx netlify-cms-proxy-server`
@@ -57,18 +57,18 @@ This document editor is located in `/src/cms/`
5757

5858
To work on the CMS locally you'll need to start both CLUE and the CMS:
5959

60-
- start CLUE by running `npm run start` in the top level folder
60+
- start CLUE by running `npm start` in the top level folder
6161
- if running the local Git proxy, start it next so it gets port 8081
6262
- in a new terminal, open the `/cms` folder
6363
- make sure its dependencies are installed: `npm i`
64-
- start the CMS by running `npm run start`
65-
- open the CMS with `http://localhost:[cms_port]/?cmsEditorBase=http://localhost:[clue_port]&unit=[clue_unit_code]&curriculumBranch=[your own branch]`
64+
- start the CMS by running `npm start`
65+
- open the CMS with `http://localhost:[cms_port]/?iframeBase=http://localhost:[clue_port]&unit=[clue_unit_code]&curriculumBranch=[your own branch]`
6666
(add `&localCMSBackend` if using it). Make sure there are no extra "#" or "/" characters in the URL.
6767

6868
Typically CLUE will be running on portal 8080 and the CMS will be running on 8081, or CLUE on 8080, Git proxy on 8081, and CMS on 8082. In this case the url above would be:
6969

70-
- No proxy: `http://localhost:8081/?cmsEditorBase=http://localhost:8080&unit=[clue_unit_code]&curriculumBranch=[your own branch]`
71-
- With proxy: `http://localhost:8082/?cmsEditorBase=http://localhost:8080&localCMSBackend&unit=[clue_unit_code]`
70+
- No proxy: `http://localhost:8081/?iframeBase=http://localhost:8080&unit=[clue_unit_code]&curriculumBranch=[your own branch]`
71+
- With proxy: `http://localhost:8082/?iframeBase=http://localhost:8080&localCMSBackend&unit=[clue_unit_code]`
7272

7373
With this approach you'll be editing the content in the `clue-curriculum` repository directly. By default this will use the `author` branch in the `clue-curriculum` repository. So you aren't making changes to the same branch as other people, you should make your own branch in that repository and pass it to the `curriculumBranch` parameter. You have to make this branch using your own git tools, the CMS cannot create branches itself.
7474

Diff for: scripts/shutterbug.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
// Example executions:
2+
//
3+
// Generate image and print out the url of the image:
4+
// npx tsx shutterbug.ts /Users/scytacki/Development/ai/dataset1720819925834-mods/documents/document-NePawLNjq3wEjk58TiW.txt
5+
//
6+
// Generate shutterbug.html for checking page locally:
7+
// npx tsx shutterbug.ts /Users/scytacki/Development/ai/dataset1720819925834-mods/documents/document-NePawLNjq3wEjk58TiW.txt html
8+
19
import fs from "fs";
210

311
function generateHtml(clueDocument: any) {
412
return `
513
<script>const initialValue=${JSON.stringify(clueDocument)}</script>
614
<iframe id='clue-frame' width='100%' height='1500px' style='border:0px'
715
allow='serial'
8-
src='https://collaborative-learning.concord.org/branch/shutterbug-support/cms-editor.html'
16+
src='https://collaborative-learning.concord.org/branch/shutterbug-support/iframe.html'
917
></iframe>
1018
<script>
1119
const clueFrame = document.getElementById('clue-frame')
@@ -38,6 +46,7 @@ export async function postToShutterbug(body: any) {
3846
}
3947

4048
const fileName = process.argv[2];
49+
const outputHtml = process.argv[3];
4150

4251
const documentString = fs.readFileSync(fileName, "utf8");
4352
const docObject = JSON.parse(documentString);
@@ -46,12 +55,13 @@ const html = generateHtml(docObject);
4655
// uncomment this line if you want to generate a local html file
4756
// this file can be opened in a web browser to see roughly what
4857
// shutterbug is seeing.
49-
// fs.writeFileSync("shutterbug.html", html);
58+
if (outputHtml) {
59+
fs.writeFileSync("shutterbug.html", html);
60+
} else {
61+
postToShutterbug({content: html, height: 1500});
62+
}
63+
//
5064

5165
// Note: you can also change the `.png` to `.html` on the end of the URL returned by shutterbug.
5266
// This will give you the actual html that shutterbug sent to its internal browser
5367

54-
postToShutterbug({content: html, height: 1500});
55-
56-
// Example execution
57-
// npx tsx shutterbug.ts /Users/scytacki/Development/ai/dataset1720819925834-mods/documents/document-NePawLNjq3wEjk58TiW.txt

Diff for: src/cms/cms-document-editor.tsx renamed to src/iframe/iframe-document-editor.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Map } from "immutable";
55
import { defaultDocumentModelParts } from "../components/doc-editor/doc-editor-app-defaults";
66
import { AppProvider, initializeApp } from "../initialize-app";
77
import { createDocumentModelWithEnv, DocumentModelType } from "../models/document/document";
8-
import { DEBUG_CMS } from "../lib/debug";
8+
import { DEBUG_IFRAME } from "../lib/debug";
99
import { EditableDocumentContent } from "../components/document/editable-document-content";
1010
import { DocumentAnnotationToolbar } from "../components/document/document-annotation-toolbar";
1111

@@ -24,7 +24,7 @@ interface IState {
2424

2525
const stores = initializeApp(true);
2626

27-
export class CmsDocumentEditor extends React.Component<IProps, IState> {
27+
export class IframeDocumentEditor extends React.Component<IProps, IState> {
2828
disposer: IDisposer;
2929
constructor(props: any) {
3030
super(props);
@@ -75,9 +75,9 @@ export class CmsDocumentEditor extends React.Component<IProps, IState> {
7575
// is a immutable object and sometimes it is a plain JS object.
7676
const immutableValue = Map(parsedJson);
7777
this.props.handleUpdateContent(immutableValue);
78-
if (DEBUG_CMS) {
78+
if (DEBUG_IFRAME) {
7979
// eslint-disable-next-line no-console
80-
console.log("DEBUG: CMS ClueControl onChange called with new content value: ", parsedJson);
80+
console.log("DEBUG: Iframe'd CLUE sending updateContent message with:", parsedJson);
8181
}
8282
}
8383
}
File renamed without changes.

Diff for: src/cms/cms-editor.tsx renamed to src/iframe/iframe.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
33

4-
import { CmsDocumentEditor } from "./cms-document-editor";
4+
import { IframeDocumentEditor } from "./iframe-document-editor";
55
import { DocumentModelType } from "../models/document/document";
66

77
let initialValue = undefined as DocumentModelType | undefined;
@@ -25,7 +25,7 @@ const handleUpdateContent = (json: Record<string, any>) => {
2525
const renderEditor = () => {
2626
ReactDOM.render(
2727
<div id="app">
28-
<CmsDocumentEditor initialValue={initialValue} handleUpdateContent={handleUpdateContent} />
28+
<IframeDocumentEditor initialValue={initialValue} handleUpdateContent={handleUpdateContent} />
2929
</div>,
3030
document.getElementById("app")
3131
);

Diff for: src/lib/debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function debugLog(enabled: boolean, message: any, ...params: any[]) {
2929

3030
export const DEBUG_BOOKMARKS = debugContains("bookmarks");
3131
export const DEBUG_CANVAS = debugContains("canvas");
32-
export const DEBUG_CMS = debugContains("cms");
32+
export const DEBUG_IFRAME = debugContains("iframe");
3333
export const DEBUG_DATAFLOW = debugContains("dataflow");
3434
export const DEBUG_DOC_LIST = debugContains("docList");
3535
export const DEBUG_DOCUMENT = debugContains("document");

Diff for: src/utilities/url-params.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ export interface QueryParams {
9090
// mouse sensor can be enabled for cypress drag and drop tests for dnd-kit
9191
mouseSensor?: boolean;
9292

93-
//
94-
// CMS options (admin.html)
95-
//
96-
97-
// change the branch used in clue-curriculum repository default is author
98-
curriculumBranch?: string;
99-
// work with a local checkout of the curriculum instead of github
100-
localCMSBackend?: boolean;
101-
// change the location of the cms-editor.html used by iframe widget to edit
102-
// CLUE documents.
103-
cmsEditorBase?: string;
104-
10593
//
10694
// Standalone document editor options (doc-editor.html)
10795
//
@@ -124,7 +112,7 @@ type BooleanParamNames = Exclude<
124112
undefined>;
125113

126114
const booleanParams: BooleanParamNames[] =
127-
[ "demo", "mouseSensor", "localCMSBackend", "noPersistentUI", "readOnly", "noStorage", "unwrapped" ];
115+
[ "demo", "mouseSensor", "noPersistentUI", "readOnly", "noStorage", "unwrapped" ];
128116

129117
const processBooleanValue = (value: string | (string | null)[] | null | undefined) => {
130118
if (value === undefined || value === "false") {

Diff for: webpack.config.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = (env, argv) => {
6161
// on the devServer start up time
6262
entry: {
6363
index: './src/index.tsx',
64-
'cms-editor': './src/cms/cms-editor.tsx',
64+
iframe: './src/iframe/iframe.tsx',
6565
'doc-editor': './src/doc-editor.tsx'
6666
},
6767
mode: devMode ? 'development' : 'production',
@@ -264,10 +264,11 @@ module.exports = (env, argv) => {
264264
}),
265265
new HtmlWebpackPlugin({
266266
...baseHtmlPluginConfig,
267-
chunks: ['cms-editor'],
268-
filename: 'cms-editor.html',
267+
chunks: ['iframe'],
268+
filename: 'iframe.html',
269269
publicPath: '.',
270-
template: 'src/cms/cms-editor.html'
270+
// Seems like we could just use the standard index.html here (it adds loading stuff but that should be harmless)
271+
template: 'src/iframe/iframe.html'
271272
}),
272273
new CopyWebpackPlugin({
273274
patterns: [

0 commit comments

Comments
 (0)