Skip to content

Commit 62bfc80

Browse files
committed
Merge branch 'main' into updated-editor-introduction
2 parents 9d86cf1 + 13318ef commit 62bfc80

File tree

94 files changed

+684
-512
lines changed

Some content is hidden

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

94 files changed

+684
-512
lines changed

public/reference/data.json

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

public/search-indices/en.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/es.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/hi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/ko.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/search-indices/zh-Hans.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/api/OpenProcessing.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export type OpenProcessingCurationResponse = Array<{
2323
title: string;
2424
/** Description of sketch */
2525
description: string;
26+
instructions: string;
27+
mode: string;
28+
createdOn: string;
2629
userID: string;
2730
submittedOn: string;
2831
/** Author's name */
@@ -36,16 +39,19 @@ export type OpenProcessingCurationResponse = Array<{
3639
* @param limit max number of sketches to return
3740
* @returns sketches
3841
*/
39-
export const getCurationSketches = async (
42+
export const getCurationSketches = memoize(async (
4043
limit?: number,
4144
): Promise<OpenProcessingCurationResponse> => {
4245
const limitParam = limit ? `limit=${limit}` : "";
4346
const response = await fetch(
4447
`${openProcessingEndpoint}curation/${curationId}/sketches?${limitParam}`,
4548
);
49+
if(!response.ok){ //log error instead of throwing error to not cache result in memoize
50+
console.error('getCurationSketches', response.status, response.statusText)
51+
}
4652
const payload = await response.json();
4753
return payload as OpenProcessingCurationResponse;
48-
};
54+
});
4955

5056
/**
5157
* API Response from a call to the Sketch endpoint
@@ -69,26 +75,50 @@ export type OpenProcessingSketchResponse = {
6975

7076
/**
7177
* Get info about a specific sketch from the OpenProcessing API
78+
* First checks if the sketch is in the memoized curated sketches and returns the data if so,
79+
* Otherwise calls OpenProcessing API for this specific sketch
7280
*
7381
* https://documenter.getpostman.com/view/16936458/2s9YC1Xa6X#7cd344f6-6e87-426a-969b-2b4a79701dd1
7482
* @param id
7583
* @returns
7684
*/
77-
export const getSketch = memoize(async (
78-
id: string,
79-
): Promise<OpenProcessingSketchResponse> => {
85+
export const getSketch = memoize(
86+
async (id: string): Promise<OpenProcessingSketchResponse> => {
87+
// check for memoized sketch in curation sketches
88+
const curationSketches = await getCurationSketches();
89+
const memoizedSketch = curationSketches.find((el) => el.visualID === id);
90+
if (memoizedSketch) {
91+
return {
92+
...memoizedSketch,
93+
license: "",
94+
} as OpenProcessingSketchResponse;
95+
}
96+
97+
// check for sketch data in Open Processing API
8098
const response = await fetch(`${openProcessingEndpoint}sketch/${id}`);
99+
if (!response.ok) {
100+
//log error instead of throwing error to not cache result in memoize
101+
console.error("getSketch", id, response.status, response.statusText);
102+
}
81103
const payload = await response.json();
82104
return payload as OpenProcessingSketchResponse;
83105
});
84106

107+
/**
108+
* Note: this currently calls `/api/sketch/:id/code`
109+
* But only uses the width and height properties from this call
110+
* Width and height should instead be added to properties for `/api/sketch/:id` or `api/curation/:curationId/sketches` instead
111+
*/
85112
export const getSketchSize = memoize(async (id: string) => {
86113
const sketch = await getSketch(id)
87114
if (sketch.mode !== 'p5js') {
88115
return { width: undefined, height: undefined };
89116
}
90117

91118
const response = await fetch(`${openProcessingEndpoint}sketch/${id}/code`);
119+
if(!response.ok){ //log error instead of throwing error to not cache result in memoize
120+
console.error('getSketchSize', id, response.status, response.statusText)
121+
}
92122
const payload = await response.json();
93123

94124
for (const tab of payload) {

src/components/CodeEmbed/frame.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, useLayoutEffect, useEffect } from "preact/hooks";
1+
import { useRef, useLayoutEffect, useEffect, useState } from "preact/hooks";
22
import { cdnLibraryUrl } from "@/src/globals/globals";
33

44
interface CodeBundle {
@@ -86,6 +86,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
8686
const p5ScriptTag = document.getElementById(
8787
"p5ScriptTag",
8888
) as HTMLScriptElement;
89+
const [mounted, setMounted] = useState(false);
8990

9091
// For performance, set the iframe to display:none when
9192
// not visible on the page. This will stop the browser
@@ -101,11 +102,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
101102
(entries) => {
102103
entries.forEach((entry) => {
103104
if (!iframeRef.current) return;
104-
if (entry.isIntersecting) {
105-
iframeRef.current.style.removeProperty("display");
106-
} else {
107-
iframeRef.current.style.display = "none";
108-
}
105+
setMounted(entry.isIntersecting);
109106
});
110107
},
111108
{ rootMargin: "20px" },
@@ -118,6 +115,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
118115
useEffect(() => {
119116
(async () => {
120117
if (!p5ScriptTag || !iframeRef.current) return;
118+
if (!mounted) return;
121119

122120
/*
123121
* Uses postMessage to receive the text content of p5.min.js, to be included
@@ -148,7 +146,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
148146
return;
149147
}
150148
})();
151-
}, [props.jsCode]);
149+
}, [props.jsCode, mounted]);
152150

153151
return (
154152
<div
@@ -157,13 +155,13 @@ export const CodeFrame = (props: CodeFrameProps) => {
157155
>
158156
<iframe
159157
ref={iframeRef}
160-
srcDoc={wrapInMarkup({
158+
srcDoc={mounted ? wrapInMarkup({
161159
js: props.jsCode,
162160
css: props.cssCode,
163161
htmlBody: props.htmlBodyCode,
164162
base: props.base,
165163
scripts: props.scripts,
166-
})}
164+
}) : undefined}
167165
sandbox="allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
168166
aria-label="Code Preview"
169167
title="Code Preview"

src/content/contributor-docs/en/contributing_to_the_p5js_reference.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ If the parameter is optional, add square brackets around the name:
120120

121121
### Additional info: Constants
122122

123-
If the parameter takes one or more values defined in [`constants.js`](https://github.com/processing/p5.js/blob/main/src/core/constants.js) , then the type should be specified as `{Constant}` and the valid values should be enumerated in the comment following the `either` keyword, e.g.:
123+
If the parameter takes one or more values defined in [`constants.js`](https://github.com/processing/p5.js/blob/main/src/core/constants.js), then the type should be specified as `{Constant}` and the valid values should be enumerated in the comment following the `either` keyword, e.g.:
124124

125125
```
126126
@param {Constant} horizAlign horizontal alignment, either LEFT, CENTER, or RIGHT
@@ -225,7 +225,7 @@ The relevant `@example` tag to create the above is as follows:
225225

226226
After the `@example` tag, you should start an HTML `<div>` tag followed by a `<code>` tag. In between the opening and closing `<code>` tag, you will insert the relevant example code. The basic principle of writing good example code for the reference is to keep things simple and minimal. The example should be meaningful and explain how the feature works without being too complicated. The example’s canvas should be 100x100 pixels and if the `setup()` function is not included, such as in the example above, the code will be automatically wrapped in a `setup()` function with a default 100x100 pixels gray background canvas created. We won’t go through the details about best practices and code style for the example code here; please see the reference style guide instead.
227227

228-
You can have multiple examples for one feature.To do so, add an additional `<div>` and `<code>` HTML block right after the first closed, separated by a blank line.
228+
You can have multiple examples for one feature. To do so, add an additional `<div>` and `<code>` HTML block right after the first closed, separated by a blank line.
229229

230230
```
231231
* @example

src/content/contributor-docs/en/contributor_guidelines.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ p5.js' code standard or code style is enforced by [ESLlint](https://eslint.org/)
386386

387387
While working on any features of p5.js, it is important to keep in mind the design principles of p5.js. Our priorities may differ from the priorities of other projects, so if you are coming from a different project, we recommend that you familiarize yourself with p5.js' design principles.
388388

389-
* **Access** We prioritize accessibility first and foremost, and decisions we make must take into account how it increases access to historically marginalized groups. Read more about this in our access statement.
389+
* **Access** We prioritize accessibility first and foremost, and decisions we make must take into account how they increase access to historically marginalized groups. Read more about this in our access statement.
390390
* **Beginner Friendly** The p5.js API aims to be friendly to beginner coders, offering a low barrier to creating interactive and visual web content with cutting-edge HTML5/Canvas/DOM APIs.
391391
* **Educational** p5.js is focused on an API and curriculum that supports educational use, including a complete reference to the API with supporting examples, as well as tutorials and sample class curricula that introduce core creative coding principles in a clear and engaging order.
392392
* **JavaScript and its community** p5.js aims to make web development practices more accessible to beginners by modeling proper JavaScript design patterns and usage while abstracting them where necessary. As an open-source library, p5.js also includes the wider JavaScript community in its creation, documentation, and dissemination.

0 commit comments

Comments
 (0)