From dcd053db1ec9bb8fe8bb8271578588159e076d4f Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 16 Jan 2024 20:36:16 -0800 Subject: [PATCH 1/5] Added test, changed startOpen --- .../__tests__/library/tag_test.ts | 9 ++++ packages/squiggle-lang/src/fr/tag.ts | 44 +++++++++++++++++++ packages/squiggle-lang/src/value/valueTags.ts | 9 ++++ 3 files changed, 62 insertions(+) diff --git a/packages/squiggle-lang/__tests__/library/tag_test.ts b/packages/squiggle-lang/__tests__/library/tag_test.ts index e4640ca5ce..9f023f7212 100644 --- a/packages/squiggle-lang/__tests__/library/tag_test.ts +++ b/packages/squiggle-lang/__tests__/library/tag_test.ts @@ -29,6 +29,15 @@ describe("Tags", () => { testEvalToBe("3 -> Tag.hide -> Tag.getHide", "true"); }); + describe("startOpenToggle", () => { + testEvalToBe("3 -> Tag.startOpen -> Tag.getStartOpenState", '"open"'); + testEvalToBe("3 -> Tag.startClosed -> Tag.getStartOpenState", '"closed"'); + testEvalToBe( + "3 -> Tag.startClosed -> Tag.startOpen -> Tag.getStartOpenState", + '"open"' + ); + }); + describe("omit", () => { testEvalToBe( "123 -> Tag.name('myName') -> Tag.doc('myDoc') -> Tag.format('.2%') -> Tag.omit(['name', 'doc']) -> Tag.getAll", diff --git a/packages/squiggle-lang/src/fr/tag.ts b/packages/squiggle-lang/src/fr/tag.ts index 71896f3ef3..5de5fc3855 100644 --- a/packages/squiggle-lang/src/fr/tag.ts +++ b/packages/squiggle-lang/src/fr/tag.ts @@ -289,6 +289,50 @@ example2 = {|x| x + 1}`, }), ], }), + maker.make({ + name: "startOpen", + description: `When the value is first displayed, it will be shown as open.`, + displaySection: "Tags", + definitions: [ + makeDefinition( + [frWithTags(frAny({ genericName: "A" }))], + frWithTags(frAny({ genericName: "A" })), + ([{ value, tags }]) => ({ + value, + tags: tags.merge({ startOpenToggle: "open" }), + }), + { isDecorator: true } + ), + ], + }), + maker.make({ + name: "startClosed", + description: `When the value is first displayed, it will be shown as collapsed.`, + displaySection: "Tags", + definitions: [ + makeDefinition( + [frWithTags(frAny({ genericName: "A" }))], + frWithTags(frAny({ genericName: "A" })), + ([{ value, tags }]) => ({ + value, + tags: tags.merge({ startOpenToggle: "closed" }), + }), + { isDecorator: true } + ), + ], + }), + maker.make({ + name: "getStartOpenState", + displaySection: "Tags", + definitions: [ + makeDefinition( + [frWithTags(frAny())], + frString, + ([{ tags }]) => tags?.value.startOpenToggle || "", + { isDecorator: true } + ), + ], + }), maker.make({ name: "notebook", description: `Displays the list of values as a notebook. This means that element indices are hidden, and the values are displayed in a vertical list. Useful for displaying combinations of text and values.`, diff --git a/packages/squiggle-lang/src/value/valueTags.ts b/packages/squiggle-lang/src/value/valueTags.ts index 6ab122dfae..29666e4893 100644 --- a/packages/squiggle-lang/src/value/valueTags.ts +++ b/packages/squiggle-lang/src/value/valueTags.ts @@ -11,6 +11,7 @@ export type ValueTagsType = { dateFormat?: string; hidden?: boolean; notebook?: boolean; + startOpenToggle?: "open" | "closed"; }; type ValueTagsTypeName = keyof ValueTagsType; @@ -23,6 +24,7 @@ const valueTagsTypeNames: ValueTagsTypeName[] = [ "dateFormat", "hidden", "notebook", + "startOpenToggle", ]; function convertToValueTagsTypeName( @@ -69,6 +71,9 @@ export class ValueTags { if (value.notebook) { result.push(["notebook", vBool(value.notebook)]); } + if (value.startOpenToggle) { + result.push(["startOpenToggle", vString(value.startOpenToggle)]); + } return result; } @@ -128,4 +133,8 @@ export class ValueTags { notebook() { return this.value.notebook; } + + startOpenToggle() { + return this.value.startOpenToggle; + } } From 3c42c6b55880bce37512f91961cb6391df5c3769 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 16 Jan 2024 20:48:16 -0800 Subject: [PATCH 2/5] Fixed components, for startOpen and startClosed --- .changeset/friendly-jobs-crash.md | 6 ++++ .../src/components/SquiggleViewer/utils.ts | 6 ++++ .../stories/SquigglePlayground.stories.tsx | 31 ++++++++++++------- packages/squiggle-lang/src/fr/tag.ts | 6 ++-- .../src/public/SqValue/SqTags.ts | 4 +++ packages/squiggle-lang/src/value/valueTags.ts | 12 +++---- 6 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 .changeset/friendly-jobs-crash.md diff --git a/.changeset/friendly-jobs-crash.md b/.changeset/friendly-jobs-crash.md new file mode 100644 index 0000000000..a3b60fd024 --- /dev/null +++ b/.changeset/friendly-jobs-crash.md @@ -0,0 +1,6 @@ +--- +"@quri/squiggle-lang": patch +"@quri/squiggle-components": patch +--- + +Added Tag.startOpen and Tag.startClosed diff --git a/packages/components/src/components/SquiggleViewer/utils.ts b/packages/components/src/components/SquiggleViewer/utils.ts index ab9c1381f3..367b1434cc 100644 --- a/packages/components/src/components/SquiggleViewer/utils.ts +++ b/packages/components/src/components/SquiggleViewer/utils.ts @@ -160,6 +160,12 @@ export const shouldBeginCollapsed = ( value: SqValueWithContext, path: SqValuePath ): boolean => { + const startOpenState = value.tags.startOpenState(); + if (startOpenState === "open") { + return false; + } else if (startOpenState === "closed") { + return true; + } const childrenValues = getChildrenValues(value); if (path.isRoot()) { return childrenValues.length > 30; diff --git a/packages/components/src/stories/SquigglePlayground.stories.tsx b/packages/components/src/stories/SquigglePlayground.stories.tsx index 9bca523e9a..dcd6efc209 100644 --- a/packages/components/src/stories/SquigglePlayground.stories.tsx +++ b/packages/components/src/stories/SquigglePlayground.stories.tsx @@ -291,17 +291,26 @@ export const Tagged: Story = { args: { defaultCode: `z = 34 -> Tag.format(".1f") - @name("My favorite Dist") - @doc("This is a long description") - @format("$.2") - x = 5 to 10 - - @showAs(Plot.numericFn) - @name("My favorite Fn") - fn = {|e| e} +@name("My favorite Dist") +@doc("This is a long description") +@format("$.2") +x = 5 to 10 - bar = [x, fn] - - y = x -> Tag.getAll`, +@showAs(Plot.numericFn) +@name("My favorite Fn") +fn = {|e| e} + +@hide +bar = [x, fn] + +@startOpen +s = 4 to 10 + +@startClosed +@showAs(Plot.numericFn) +@name("My favorite Fn2") +fn2 = {|e| e} + +y = x -> Tag.getAll`, }, }; diff --git a/packages/squiggle-lang/src/fr/tag.ts b/packages/squiggle-lang/src/fr/tag.ts index 5de5fc3855..eb7136c722 100644 --- a/packages/squiggle-lang/src/fr/tag.ts +++ b/packages/squiggle-lang/src/fr/tag.ts @@ -299,7 +299,7 @@ example2 = {|x| x + 1}`, frWithTags(frAny({ genericName: "A" })), ([{ value, tags }]) => ({ value, - tags: tags.merge({ startOpenToggle: "open" }), + tags: tags.merge({ startOpenState: "open" }), }), { isDecorator: true } ), @@ -315,7 +315,7 @@ example2 = {|x| x + 1}`, frWithTags(frAny({ genericName: "A" })), ([{ value, tags }]) => ({ value, - tags: tags.merge({ startOpenToggle: "closed" }), + tags: tags.merge({ startOpenState: "closed" }), }), { isDecorator: true } ), @@ -328,7 +328,7 @@ example2 = {|x| x + 1}`, makeDefinition( [frWithTags(frAny())], frString, - ([{ tags }]) => tags?.value.startOpenToggle || "", + ([{ tags }]) => tags?.value.startOpenState || "", { isDecorator: true } ), ], diff --git a/packages/squiggle-lang/src/public/SqValue/SqTags.ts b/packages/squiggle-lang/src/public/SqValue/SqTags.ts index cd2798dd77..0d9a6f6937 100644 --- a/packages/squiggle-lang/src/public/SqValue/SqTags.ts +++ b/packages/squiggle-lang/src/public/SqValue/SqTags.ts @@ -36,4 +36,8 @@ export class SqTags { notebook(): boolean | undefined { return this.tags.notebook(); } + + startOpenState(): "open" | "closed" | undefined { + return this.tags.startOpenState(); + } } diff --git a/packages/squiggle-lang/src/value/valueTags.ts b/packages/squiggle-lang/src/value/valueTags.ts index 29666e4893..ef1ce8fe9a 100644 --- a/packages/squiggle-lang/src/value/valueTags.ts +++ b/packages/squiggle-lang/src/value/valueTags.ts @@ -11,7 +11,7 @@ export type ValueTagsType = { dateFormat?: string; hidden?: boolean; notebook?: boolean; - startOpenToggle?: "open" | "closed"; + startOpenState?: "open" | "closed"; }; type ValueTagsTypeName = keyof ValueTagsType; @@ -24,7 +24,7 @@ const valueTagsTypeNames: ValueTagsTypeName[] = [ "dateFormat", "hidden", "notebook", - "startOpenToggle", + "startOpenState", ]; function convertToValueTagsTypeName( @@ -71,8 +71,8 @@ export class ValueTags { if (value.notebook) { result.push(["notebook", vBool(value.notebook)]); } - if (value.startOpenToggle) { - result.push(["startOpenToggle", vString(value.startOpenToggle)]); + if (value.startOpenState) { + result.push(["startOpenState", vString(value.startOpenState)]); } return result; } @@ -134,7 +134,7 @@ export class ValueTags { return this.value.notebook; } - startOpenToggle() { - return this.value.startOpenToggle; + startOpenState() { + return this.value.startOpenState; } } From 3b02af062f4c3e10a3ecc399c11c9ddfeedce7f3 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 16 Jan 2024 20:50:54 -0800 Subject: [PATCH 3/5] Documentation fix for startOpen startClosed --- packages/squiggle-lang/src/fr/tag.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/squiggle-lang/src/fr/tag.ts b/packages/squiggle-lang/src/fr/tag.ts index eb7136c722..f8f39aa701 100644 --- a/packages/squiggle-lang/src/fr/tag.ts +++ b/packages/squiggle-lang/src/fr/tag.ts @@ -291,7 +291,7 @@ example2 = {|x| x + 1}`, }), maker.make({ name: "startOpen", - description: `When the value is first displayed, it will be shown as open.`, + description: `When the value is first displayed, it will begin open in the viewer. Refresh the page to reset.`, displaySection: "Tags", definitions: [ makeDefinition( @@ -307,7 +307,7 @@ example2 = {|x| x + 1}`, }), maker.make({ name: "startClosed", - description: `When the value is first displayed, it will be shown as collapsed.`, + description: `When the value is first displayed, it will begin collapsed in the viewer. Refresh the page to reset.`, displaySection: "Tags", definitions: [ makeDefinition( @@ -324,6 +324,7 @@ example2 = {|x| x + 1}`, maker.make({ name: "getStartOpenState", displaySection: "Tags", + description: `Returns the startOpenState of a value, which can be "open", "closed", or "" if no startOpenState is set. Set using \`Tag.startOpen\` and \`Tag.startClosed\`.`, definitions: [ makeDefinition( [frWithTags(frAny())], From e96e82feba54491efc1eb98a991611d21e20b859 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 16 Jan 2024 20:52:01 -0800 Subject: [PATCH 4/5] Update friendly-jobs-crash.md --- .changeset/friendly-jobs-crash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/friendly-jobs-crash.md b/.changeset/friendly-jobs-crash.md index a3b60fd024..7c092c0f94 100644 --- a/.changeset/friendly-jobs-crash.md +++ b/.changeset/friendly-jobs-crash.md @@ -3,4 +3,4 @@ "@quri/squiggle-components": patch --- -Added Tag.startOpen and Tag.startClosed +Added Tag.startOpen, Tag.startClosed, and Tag.getStartOpenState From e0ce8cd77a83da3d9236908bb76d22da337e0737 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 17 Jan 2024 13:06:48 -0800 Subject: [PATCH 5/5] Update packages/squiggle-lang/src/fr/tag.ts Co-authored-by: Vyacheslav Matyukhin --- packages/squiggle-lang/src/fr/tag.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/squiggle-lang/src/fr/tag.ts b/packages/squiggle-lang/src/fr/tag.ts index f8f39aa701..629eddabee 100644 --- a/packages/squiggle-lang/src/fr/tag.ts +++ b/packages/squiggle-lang/src/fr/tag.ts @@ -330,7 +330,6 @@ example2 = {|x| x + 1}`, [frWithTags(frAny())], frString, ([{ tags }]) => tags?.value.startOpenState || "", - { isDecorator: true } ), ], }),