Skip to content

Commit

Permalink
chore: changes according to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
raaymax committed Feb 28, 2024
1 parent db4b403 commit e624faa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ui/src/builder/BuilderFieldsText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const options = computed(() => {
const field = templateField.value;
if (field.options) {
return typeof field.options === "function"
? field.options()
? field.options(ss, componentId.value)
: field.options;
}
return [];
Expand Down
23 changes: 10 additions & 13 deletions ui/src/core_components/content/CoreLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
</template>

<script lang="ts">
import { FieldType } from "../../streamsyncTypes";
import { FieldType, Core } from "../../streamsyncTypes";
import { cssClasses, primaryTextColor } from "../../renderer/sharedStyleFields";
import injectionKeys from "../../injectionKeys";
let options = [];
export default {
streamsync: {
name: "Link",
Expand All @@ -26,7 +24,15 @@ export default {
name: "URL",
type: FieldType.Text,
desc: "A valid URL.",
options: () => Object.fromEntries(options.value),
options: (ss: Core) => {
return Object.fromEntries(
ss
.getComponents("root", true)
.map((page) => page.content.key)
.filter((key) => Boolean(key))
.map((key) => [`#${key}`, key]),
);
},
},
target: {
name: "Target",
Expand Down Expand Up @@ -60,17 +66,8 @@ export default {

<script setup lang="ts">
import { inject, computed } from "vue";
const ss = inject(injectionKeys.core);
const fields = inject(injectionKeys.evaluatedFields);
options = computed(() => {
return ss
.getComponents("root", true)
.map((page) => page.content.key)
.filter((key) => Boolean(key))
.map((key) => [`#${key}`, key]);
});
const displayText = computed(() => {
return fields.text.value || fields.url.value || "Link";
});
Expand Down
14 changes: 11 additions & 3 deletions ui/src/streamsyncTypes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { generateCore } from "./core";
import { generateBuilderManager } from "./builder/builderManager";

export type Core = ReturnType<typeof generateCore>;

type ComponentId = string;

/**
* Basic building block of applications.
* Multiple instances of a single component can exists. For example, via Repeater.
*/

export type Component = {
id: string;
id: ComponentId;
parentId: string;
type: string;
position: number;
Expand Down Expand Up @@ -54,7 +58,12 @@ export type StreamsyncComponentDefinition = {
desc?: string; // Description
default?: string; // Value used if the field is empty, e.g. "(No text)"
control?: FieldControl; // Which control (text, textarea, etc) to use if not the default for the type
options?: Record<string, string> | (() => Record<string, string>); // List of values to be provided as autocomplete options
options?:
| Record<string, string>
| ((
ss?: Core,
componentId?: ComponentId,
) => Record<string, string>); // List of values to be provided as autocomplete options
type: FieldType; // Data type for the field
category?: FieldCategory; // Category (Layout, Content, etc)
applyStyleVariable?: boolean; // Use the value of this field as a CSS variable
Expand All @@ -72,7 +81,6 @@ export type StreamsyncComponentDefinition = {
positionless?: boolean; // Whether this type of component is positionless (like Sidebar)
};

export type Core = ReturnType<typeof generateCore>;
export type BuilderManager = ReturnType<typeof generateBuilderManager>;

export const enum ClipboardOperation {
Expand Down

0 comments on commit e624faa

Please sign in to comment.