generated from deco-sites/fashion
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from deco-sites/feat/prop-editing
feat: prop editing
- Loading branch information
Showing
9 changed files
with
360 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"daisyui": "npm:[email protected]" | ||
}, | ||
"tasks": { | ||
"start": "deno task bundle && deno run -A --unstable --env --watch=tailwind.css,sections/,functions/,loaders/,actions/,workflows/,accounts/,.env dev.ts", | ||
"start": "deno task generate-icons && deno task bundle && deno run -A --unstable --env --watch=tailwind.css,sections/,functions/,loaders/,actions/,workflows/,accounts/,.env dev.ts", | ||
"gen": "deno run -A dev.ts --gen-only", | ||
"play": "USE_LOCAL_STORAGE_ONLY=true deno task start", | ||
"component": "deno eval 'import \"deco/scripts/component.ts\"'", | ||
|
@@ -26,7 +26,8 @@ | |
"bundle": "deno eval 'import \"deco/scripts/apps/bundle.ts\"' deco-sites/storefront", | ||
"cache_clean": "rm deno.lock; deno cache -r main.ts", | ||
"build": "deno run -A dev.ts build", | ||
"preview": "deno run -A main.ts" | ||
"preview": "deno run -A main.ts", | ||
"generate-icons": "deno run -A --unstable static/generate-icons.ts" | ||
}, | ||
"githooks": { | ||
"pre-commit": "check" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { allowCorsFor, FnContext } from "deco/mod.ts"; | ||
import { AvailableIcons } from "../static/adminIcons.ts"; | ||
|
||
const icons = Object.keys(AvailableIcons).map((iconName) => ({ | ||
component: AvailableIcons[iconName as keyof typeof AvailableIcons], | ||
label: iconName, | ||
})); | ||
|
||
// Used to load all available icons that will be used for IconSelect widgets. | ||
export default function IconsLoader( | ||
_props: unknown, | ||
req: Request, | ||
ctx: FnContext, | ||
) { | ||
// Allow Cors | ||
Object.entries(allowCorsFor(req)).map(([name, value]) => { | ||
ctx.response.headers.set(name, value); | ||
}); | ||
|
||
// Mapping icons to { value, label, icon } | ||
const iconsMap = icons.map((icon) => ({ | ||
icon: icon.component, | ||
label: icon.label, | ||
value: icon.label, | ||
})); | ||
|
||
return iconsMap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { allowCorsFor, FnContext } from "deco/mod.ts"; | ||
import { | ||
AlignCenter, | ||
AlignLeft, | ||
AlignRight, | ||
Center, | ||
Default, | ||
Left, | ||
Lettercase, | ||
Lowercase, | ||
Right, | ||
Uppercase, | ||
} from "../static/adminIcons.ts"; | ||
|
||
const icons = [ | ||
{ component: Left, label: "Left", prop: "alignment" }, | ||
{ component: Center, label: "Center", prop: "alignment" }, | ||
{ component: Right, label: "Right", prop: "alignment" }, | ||
{ component: AlignLeft, label: "Left", prop: "textAlignment" }, | ||
{ component: AlignCenter, label: "Center", prop: "textAlignment" }, | ||
{ component: AlignRight, label: "Right", prop: "textAlignment" }, | ||
{ component: Default, label: "Default", prop: "case" }, | ||
{ component: Lowercase, label: "Lowercase", prop: "case" }, | ||
{ component: Lettercase, label: "Titlecase", prop: "case" }, | ||
{ component: Uppercase, label: "Uppercase", prop: "case" }, | ||
{ component: "S", label: "Small", prop: "fontSize" }, | ||
{ component: "M", label: "Normal", prop: "fontSize" }, | ||
{ component: "L", label: "Large", prop: "fontSize" }, | ||
]; | ||
|
||
// Used to load icons that will be used for ButtonGroup widgets. | ||
// The file adminIcons.ts contains all available icons in a string format, and this loader maps them to the format expected by the button-group widget. | ||
export default function IconsLoader( | ||
_props: unknown, | ||
req: Request, | ||
ctx: FnContext, | ||
) { | ||
// Allow Cors | ||
Object.entries(allowCorsFor(req)).map(([name, value]) => { | ||
ctx.response.headers.set(name, value); | ||
}); | ||
|
||
// Mapping icons to { value, label } | ||
const iconsMap = icons.map((icon) => ({ | ||
value: icon.component, | ||
label: icon.label, | ||
prop: icon.prop, | ||
})); | ||
|
||
return iconsMap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { existsSync } from 'https://deno.land/std/fs/mod.ts'; | ||
|
||
const svgFilePath = "static/sprites.svg"; | ||
const outputFilePath = "static/adminIcons.ts"; | ||
|
||
async function generateIconsFile() { | ||
const svgContent = await Deno.readTextFile(svgFilePath); | ||
let existingContent = ''; | ||
let existingIcons = new Set(); | ||
let newIcons = []; | ||
|
||
// Verifies if adminIcons.ts already exists and reads the icons from there | ||
if (existsSync(outputFilePath)) { | ||
existingContent = await Deno.readTextFile(outputFilePath); | ||
const regexExtract = /export const (\w+) =/g; | ||
let matchExtract; | ||
while ((matchExtract = regexExtract.exec(existingContent)) !== null) { | ||
existingIcons.add(matchExtract[1]); | ||
} | ||
} | ||
|
||
const regex = /<symbol id="(.+?)"(.+?)>(.+?)<\/symbol>/gs; | ||
let matchSymbol; | ||
while ((matchSymbol = regex.exec(svgContent)) !== null) { | ||
const [_, id, attributes, content] = matchSymbol; | ||
// Adds only new icons | ||
if (!existingIcons.has(id)) { | ||
newIcons.push(id); | ||
const iconString = `export const ${id} = \`<svg id="${id}"${attributes}>${content}</svg>\`;\n`; | ||
existingContent += iconString; | ||
} | ||
} | ||
|
||
// If there are new icons, update AvailableIcons and the file | ||
if (newIcons.length > 0) { | ||
// Remove the existing AvailableIcons constant from the content | ||
existingContent = existingContent.replace(/export const AvailableIcons = { [^}]* };/g, ''); | ||
// Adds all existing icons plus the new ones to the AvailableIcons constant | ||
const allIcons = [...existingIcons, ...newIcons]; | ||
const availableIconsString = `export const AvailableIcons = { ${allIcons.join(', ')} };`; | ||
existingContent += `\n${availableIconsString}`; | ||
|
||
await Deno.writeTextFile(outputFilePath, existingContent, { create: true }); | ||
console.log('adminIcons.ts updated successfully with new icons.'); | ||
} else { | ||
console.log('No new icons to add.'); | ||
} | ||
} | ||
|
||
generateIconsFile().catch(console.error); |