mirror of
https://github.com/penpot/penpot.git
synced 2025-01-06 14:50:20 -05:00
Merge remote-tracking branch 'penpot/develop' into token-studio-develop
This commit is contained in:
commit
cbfcc50563
27 changed files with 3021 additions and 2806 deletions
|
@ -1,5 +1,11 @@
|
|||
# CHANGELOG
|
||||
|
||||
## 2.0.3
|
||||
|
||||
### :bug: Bugs fixed
|
||||
|
||||
- Fix chrome scrollbar styling [Taiga Issue #7852](https://tree.taiga.io/project/penpot/issue/7852)
|
||||
|
||||
## 2.0.2
|
||||
|
||||
### :sparkles: Enhancements
|
||||
|
@ -10,6 +16,7 @@
|
|||
### :bug: Bugs fixed
|
||||
|
||||
- Fix color palette sorting [Taiga Issue #7458](https://tree.taiga.io/project/penpot/issue/7458)
|
||||
- Fix style scoping problem with imported SVG [Taiga #7671](https://tree.taiga.io/project/penpot/issue/7671)
|
||||
|
||||
## 2.0.1
|
||||
|
||||
|
|
|
@ -274,6 +274,13 @@
|
|||
(catch #?(:clj Throwable :cljs :default) _cause
|
||||
[0 0 0])))
|
||||
|
||||
(defn hex->lum
|
||||
[color]
|
||||
(let [[r g b] (hex->rgb color)]
|
||||
(mth/sqrt (+ (* 0.241 r)
|
||||
(* 0.691 g)
|
||||
(* 0.068 b)))))
|
||||
|
||||
(defn- int->hex
|
||||
"Convert integer to hex string"
|
||||
[v]
|
||||
|
@ -455,3 +462,19 @@
|
|||
|
||||
:else
|
||||
[r g (inc b)]))
|
||||
|
||||
(defn reduce-range
|
||||
[value range]
|
||||
(/ (mth/floor (* value range)) range))
|
||||
|
||||
(defn sort-colors
|
||||
[a b]
|
||||
(let [[ah _ av] (hex->hsv (:color a))
|
||||
[bh _ bv] (hex->hsv (:color b))
|
||||
ah (reduce-range (/ ah 60) 8)
|
||||
bh (reduce-range (/ bh 60) 8)
|
||||
av (/ av 255)
|
||||
bv (/ bv 255)
|
||||
a (+ (* ah 100) (* av 10))
|
||||
b (+ (* bh 100) (* bv 10))]
|
||||
(compare a b)))
|
||||
|
|
|
@ -3,8 +3,8 @@ LABEL maintainer="Andrey Antukh <niwi@niwi.nz>"
|
|||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
ENV NODE_VERSION=v20.11.1 \
|
||||
CLOJURE_VERSION=1.11.1.1435 \
|
||||
ENV NODE_VERSION=v20.13.1 \
|
||||
CLOJURE_VERSION=1.11.3.1463 \
|
||||
CLJKONDO_VERSION=2024.03.13 \
|
||||
BABASHKA_VERSION=1.3.189 \
|
||||
CLJFMT_VERSION=0.12.0 \
|
||||
|
@ -105,12 +105,12 @@ RUN set -eux; \
|
|||
ARCH="$(dpkg --print-architecture)"; \
|
||||
case "${ARCH}" in \
|
||||
aarch64|arm64) \
|
||||
ESUM='3ce6a2b357e2ef45fd6b53d6587aa05bfec7771e7fb982f2c964f6b771b7526a'; \
|
||||
BINARY_URL='https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2%2B13/OpenJDK21U-jdk_aarch64_linux_hotspot_21.0.2_13.tar.gz'; \
|
||||
ESUM='7d3ab0e8eba95bd682cfda8041c6cb6fa21e09d0d9131316fd7c96c78969de31'; \
|
||||
BINARY_URL='https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.3%2B9/OpenJDK21U-jdk_aarch64_linux_hotspot_21.0.3_9.tar.gz'; \
|
||||
;; \
|
||||
amd64|x86_64) \
|
||||
ESUM='454bebb2c9fe48d981341461ffb6bf1017c7b7c6e15c6b0c29b959194ba3aaa5'; \
|
||||
BINARY_URL='https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2%2B13/OpenJDK21U-jdk_x64_linux_hotspot_21.0.2_13.tar.gz'; \
|
||||
ESUM='fffa52c22d797b715a962e6c8d11ec7d79b90dd819b5bc51d62137ea4b22a340'; \
|
||||
BINARY_URL='https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.3%2B9/OpenJDK21U-jdk_x64_linux_hotspot_21.0.3_9.tar.gz'; \
|
||||
;; \
|
||||
*) \
|
||||
echo "Unsupported arch: ${ARCH}"; \
|
||||
|
|
|
@ -17,8 +17,8 @@ export default defineConfig({
|
|||
forbidOnly: !!process.env.CI,
|
||||
/* Retry on CI only */
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
/* Opt out of parallel tests on CI. */
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
/* Opt out of parallel tests by default; can be overriden with --workers */
|
||||
workers: 1,
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
reporter: "html",
|
||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -28,9 +28,16 @@ body {
|
|||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
scrollbar-width: thin;
|
||||
// transition: all .4s ease;
|
||||
}
|
||||
|
||||
@-moz-document url-prefix() {
|
||||
* {
|
||||
scrollbar-width: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.global-zeroclipboard-container {
|
||||
transition: none;
|
||||
|
||||
|
|
|
@ -6,10 +6,14 @@
|
|||
|
||||
// SCROLLBAR
|
||||
.new-scrollbar {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: rgba(170, 181, 186, 0.3) transparent;
|
||||
&:hover {
|
||||
scrollbar-color: rgba(170, 181, 186, 0.7) transparent;
|
||||
}
|
||||
|
||||
// These rules do not apply in chrome - 121 or higher
|
||||
// We keep them to preserve backward compatibility.
|
||||
::-webkit-scrollbar {
|
||||
background-color: transparent;
|
||||
cursor: pointer;
|
||||
|
|
|
@ -19,19 +19,22 @@ function getCoreCount() {
|
|||
return os.cpus().length;
|
||||
}
|
||||
|
||||
// const __filename = url.fileURLToPath(import.meta.url);
|
||||
export const dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
||||
|
||||
export function startWorker() {
|
||||
return wpool.pool(dirname + "/_worker.js", {
|
||||
maxWorkers: getCoreCount()
|
||||
maxWorkers: getCoreCount(),
|
||||
});
|
||||
}
|
||||
|
||||
async function findFiles(basePath, predicate, options={}) {
|
||||
predicate = predicate ?? function() { return true; }
|
||||
async function findFiles(basePath, predicate, options = {}) {
|
||||
predicate =
|
||||
predicate ??
|
||||
function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
let files = await fs.readdir(basePath, {recursive: options.recursive ?? false})
|
||||
let files = await fs.readdir(basePath, { recursive: options.recursive ?? false });
|
||||
files = files.map((path) => ph.join(basePath, path));
|
||||
|
||||
return files;
|
||||
|
@ -42,8 +45,11 @@ function syncDirs(originPath, destPath) {
|
|||
|
||||
return new Promise((resolve, reject) => {
|
||||
proc.exec(command, (cause, stdout) => {
|
||||
if (cause) { reject(cause); }
|
||||
else { resolve(); }
|
||||
if (cause) {
|
||||
reject(cause);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -71,28 +77,30 @@ export async function compileSassAll(worker) {
|
|||
const limitFn = pLimit(4);
|
||||
const sourceDir = "src";
|
||||
|
||||
let files = await fs.readdir(sourceDir, { recursive: true })
|
||||
let files = await fs.readdir(sourceDir, { recursive: true });
|
||||
files = files.filter((path) => path.endsWith(".scss"));
|
||||
files = files.map((path) => ph.join(sourceDir, path));
|
||||
// files = files.slice(0, 10);
|
||||
|
||||
const procs = [
|
||||
compileSass(worker, "resources/styles/main-default.scss", {}),
|
||||
compileSass(worker, "resources/styles/debug.scss", {})
|
||||
compileSass(worker, "resources/styles/debug.scss", {}),
|
||||
];
|
||||
|
||||
for (let path of files) {
|
||||
const proc = limitFn(() => compileSass(worker, path, {modules: true}));
|
||||
const proc = limitFn(() => compileSass(worker, path, { modules: true }));
|
||||
procs.push(proc);
|
||||
}
|
||||
|
||||
const result = await Promise.all(procs);
|
||||
|
||||
return result.reduce((acc, item, index) => {
|
||||
acc.index[item.outputPath] = item.css;
|
||||
acc.items.push(item.outputPath);
|
||||
return acc;
|
||||
}, {index:{}, items: []});
|
||||
return result.reduce(
|
||||
(acc, item, index) => {
|
||||
acc.index[item.outputPath] = item.css;
|
||||
acc.items.push(item.outputPath);
|
||||
return acc;
|
||||
},
|
||||
{ index: {}, items: [] },
|
||||
);
|
||||
}
|
||||
|
||||
function compare(a, b) {
|
||||
|
@ -106,7 +114,7 @@ function compare(a, b) {
|
|||
}
|
||||
|
||||
export function concatSass(data) {
|
||||
const output = []
|
||||
const output = [];
|
||||
|
||||
for (let path of data.items) {
|
||||
output.push(data.index[path]);
|
||||
|
@ -118,10 +126,9 @@ export function concatSass(data) {
|
|||
export async function watch(baseDir, predicate, callback) {
|
||||
predicate = predicate ?? (() => true);
|
||||
|
||||
|
||||
const watcher = new Watcher(baseDir, {
|
||||
persistent: true,
|
||||
recursive: true
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
watcher.on("change", (path) => {
|
||||
|
@ -133,7 +140,7 @@ export async function watch(baseDir, predicate, callback) {
|
|||
|
||||
async function readShadowManifest() {
|
||||
try {
|
||||
const manifestPath = "resources/public/js/manifest.json"
|
||||
const manifestPath = "resources/public/js/manifest.json";
|
||||
let content = await fs.readFile(manifestPath, { encoding: "utf8" });
|
||||
content = JSON.parse(content);
|
||||
|
||||
|
@ -148,7 +155,6 @@ async function readShadowManifest() {
|
|||
|
||||
return index;
|
||||
} catch (cause) {
|
||||
// log.error("error on reading manifest (using default)", cause);
|
||||
return {
|
||||
config: "js/config.js",
|
||||
polyfills: "js/polyfills.js",
|
||||
|
@ -160,14 +166,14 @@ async function readShadowManifest() {
|
|||
}
|
||||
}
|
||||
|
||||
async function renderTemplate(path, context={}, partials={}) {
|
||||
const content = await fs.readFile(path, {encoding: "utf-8"});
|
||||
async function renderTemplate(path, context = {}, partials = {}) {
|
||||
const content = await fs.readFile(path, { encoding: "utf-8" });
|
||||
|
||||
const ts = Math.floor(new Date());
|
||||
|
||||
context = Object.assign({}, context, {
|
||||
ts: ts,
|
||||
isDebug: process.env.NODE_ENV !== "production"
|
||||
isDebug: process.env.NODE_ENV !== "production",
|
||||
});
|
||||
|
||||
return mustache.render(content, context, partials);
|
||||
|
@ -214,9 +220,8 @@ async function readTranslations() {
|
|||
// this happens when file does not matches correct
|
||||
// iso code for the language.
|
||||
["ja_jp", "jpn_JP"],
|
||||
// ["fi", "fin_FI"],
|
||||
["uk", "ukr_UA"],
|
||||
"ha"
|
||||
"ha",
|
||||
];
|
||||
const result = {};
|
||||
|
||||
|
@ -261,10 +266,6 @@ async function readTranslations() {
|
|||
}
|
||||
});
|
||||
}
|
||||
// if (key === "modals.delete-font.title") {
|
||||
// console.dir(trdata[key], {depth:10});
|
||||
// console.dir(result[key], {depth:10});
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,13 +275,13 @@ async function readTranslations() {
|
|||
async function generateSvgSprite(files, prefix) {
|
||||
const spriter = new SVGSpriter({
|
||||
mode: {
|
||||
symbol: { inline: true }
|
||||
}
|
||||
symbol: { inline: true },
|
||||
},
|
||||
});
|
||||
|
||||
for (let path of files) {
|
||||
const name = `${prefix}${ph.basename(path)}`
|
||||
const content = await fs.readFile(path, {encoding: "utf-8"});
|
||||
const name = `${prefix}${ph.basename(path)}`;
|
||||
const content = await fs.readFile(path, { encoding: "utf-8" });
|
||||
spriter.add(name, name, content);
|
||||
}
|
||||
|
||||
|
@ -302,6 +303,7 @@ async function generateSvgSprites() {
|
|||
}
|
||||
|
||||
async function generateTemplates() {
|
||||
const isDebug = process.env.NODE_ENV !== "production";
|
||||
await fs.mkdir("./resources/public/", { recursive: true });
|
||||
|
||||
const translations = await readTranslations();
|
||||
|
@ -315,13 +317,19 @@ async function generateTemplates() {
|
|||
"../public/images/sprites/symbol/cursors.svg": cursorsSprite,
|
||||
};
|
||||
|
||||
const pluginRuntimeUri = (process.env.PENPOT_PLUGIN_DEV === "true") ? "http://localhost:4200" : "./plugins-runtime";
|
||||
const pluginRuntimeUri =
|
||||
process.env.PENPOT_PLUGIN_DEV === "true" ? "http://localhost:4200" : "./plugins-runtime";
|
||||
|
||||
content = await renderTemplate("resources/templates/index.mustache", {
|
||||
manifest: manifest,
|
||||
translations: JSON.stringify(translations),
|
||||
pluginRuntimeUri,
|
||||
}, partials);
|
||||
content = await renderTemplate(
|
||||
"resources/templates/index.mustache",
|
||||
{
|
||||
manifest: manifest,
|
||||
translations: JSON.stringify(translations),
|
||||
pluginRuntimeUri,
|
||||
isDebug,
|
||||
},
|
||||
partials,
|
||||
);
|
||||
|
||||
await fs.writeFile("./resources/public/index.html", content);
|
||||
|
||||
|
@ -351,7 +359,7 @@ export async function compileStyles() {
|
|||
const worker = startWorker();
|
||||
const start = process.hrtime();
|
||||
|
||||
log.info("init: compile styles")
|
||||
log.info("init: compile styles");
|
||||
let result = await compileSassAll(worker);
|
||||
result = concatSass(result);
|
||||
|
||||
|
@ -365,7 +373,7 @@ export async function compileStyles() {
|
|||
|
||||
export async function compileSvgSprites() {
|
||||
const start = process.hrtime();
|
||||
log.info("init: compile svgsprite")
|
||||
log.info("init: compile svgsprite");
|
||||
await generateSvgSprites();
|
||||
const end = process.hrtime(start);
|
||||
log.info("done: compile svgsprite", `(${ppt(end)})`);
|
||||
|
@ -373,7 +381,7 @@ export async function compileSvgSprites() {
|
|||
|
||||
export async function compileTemplates() {
|
||||
const start = process.hrtime();
|
||||
log.info("init: compile templates")
|
||||
log.info("init: compile templates");
|
||||
await generateTemplates();
|
||||
const end = process.hrtime(start);
|
||||
log.info("done: compile templates", `(${ppt(end)})`);
|
||||
|
@ -381,13 +389,12 @@ export async function compileTemplates() {
|
|||
|
||||
export async function compilePolyfills() {
|
||||
const start = process.hrtime();
|
||||
log.info("init: compile polyfills")
|
||||
|
||||
log.info("init: compile polyfills");
|
||||
|
||||
const files = await findFiles("resources/polyfills/", isJsFile);
|
||||
let result = [];
|
||||
for (let path of files) {
|
||||
const content = await fs.readFile(path, {encoding:"utf-8"});
|
||||
const content = await fs.readFile(path, { encoding: "utf-8" });
|
||||
result.push(content);
|
||||
}
|
||||
|
||||
|
@ -400,7 +407,7 @@ export async function compilePolyfills() {
|
|||
|
||||
export async function copyAssets() {
|
||||
const start = process.hrtime();
|
||||
log.info("init: copy assets")
|
||||
log.info("init: copy assets");
|
||||
|
||||
await syncDirs("resources/images/", "resources/public/images/");
|
||||
await syncDirs("resources/fonts/", "resources/public/fonts/");
|
||||
|
@ -409,4 +416,3 @@ export async function copyAssets() {
|
|||
const end = process.hrtime(start);
|
||||
log.info("done: copy assets", `(${ppt(end)})`);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,6 @@
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
.demo-account,
|
||||
.go-back {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
@ -67,7 +66,6 @@
|
|||
border-block-start: none;
|
||||
}
|
||||
|
||||
.demo-account-link,
|
||||
.go-back-link {
|
||||
@extend .button-secondary;
|
||||
@include uppercaseTitleTipography;
|
||||
|
@ -81,7 +79,8 @@
|
|||
|
||||
.register,
|
||||
.account,
|
||||
.recovery-request {
|
||||
.recovery-request,
|
||||
.demo-account {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: $s-8;
|
||||
|
@ -90,7 +89,8 @@
|
|||
|
||||
.register-text,
|
||||
.account-text,
|
||||
.recovery-text {
|
||||
.recovery-text,
|
||||
.demo-account-text {
|
||||
@include smallTitleTipography;
|
||||
text-align: right;
|
||||
color: var(--title-foreground-color);
|
||||
|
@ -99,7 +99,8 @@
|
|||
.register-link,
|
||||
.account-link,
|
||||
.recovery-link,
|
||||
.forgot-pass-link {
|
||||
.forgot-pass-link,
|
||||
.demo-account-link {
|
||||
@include smallTitleTipography;
|
||||
text-align: left;
|
||||
background-color: transparent;
|
||||
|
|
|
@ -158,7 +158,7 @@
|
|||
[:*
|
||||
(when-let [message @error]
|
||||
[:& context-notification
|
||||
{:type :warning
|
||||
{:type :error
|
||||
:content message
|
||||
:data-test "login-banner"
|
||||
:role "alert"}])
|
||||
|
@ -300,11 +300,13 @@
|
|||
[:& lk/link {:action go-register
|
||||
:class (stl/css :register-link)
|
||||
:data-test "register-submit"}
|
||||
(tr "auth.register-submit")]])]
|
||||
(tr "auth.register-submit")]])
|
||||
|
||||
(when (contains? cf/flags :demo-users)
|
||||
[:div {:class (stl/css :link-entry :demo-account)}
|
||||
[:span (tr "auth.create-demo-profile") " "]
|
||||
[:& lk/link {:action create-demo-profile
|
||||
:data-test "demo-account-link"}
|
||||
(tr "auth.create-demo-account")]])]))
|
||||
(when (contains? cf/flags :demo-users)
|
||||
[:div {:class (stl/css :demo-account)}
|
||||
[:span {:class (stl/css :demo-account-text)}
|
||||
(tr "auth.create-demo-profile") " "]
|
||||
[:& lk/link {:action create-demo-profile
|
||||
:class (stl/css :demo-account-link)
|
||||
:data-test "demo-account-link"}
|
||||
(tr "auth.create-demo-account")]])]]))
|
||||
|
|
|
@ -12,5 +12,6 @@
|
|||
margin-top: $s-8;
|
||||
padding: $s-12;
|
||||
background-color: var(--menu-background-color);
|
||||
color: var(--input-foreground-color-active);
|
||||
overflow: auto;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
(def current-page-id (mf/create-context nil))
|
||||
(def current-file-id (mf/create-context nil))
|
||||
(def current-vbox (mf/create-context nil))
|
||||
(def current-svg-root-id (mf/create-context nil))
|
||||
|
||||
(def active-frames (mf/create-context nil))
|
||||
(def render-thumbnails (mf/create-context nil))
|
||||
|
|
|
@ -85,8 +85,6 @@
|
|||
color: var(--title-foreground-color-hover);
|
||||
cursor: pointer;
|
||||
height: $s-16;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-wrapper {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
(mf/fnc group-shape
|
||||
{::mf/wrap-props false}
|
||||
[props]
|
||||
|
||||
(let [shape (unchecked-get props "shape")
|
||||
childs (unchecked-get props "childs")
|
||||
render-id (mf/use-ctx muc/render-id)
|
||||
|
@ -36,21 +37,31 @@
|
|||
|
||||
mask-props (if ^boolean masked-group?
|
||||
#js {:mask (mask-url render-id mask)}
|
||||
#js {})]
|
||||
#js {})
|
||||
|
||||
current-svg-root-id (mf/use-ctx muc/current-svg-root-id)
|
||||
|
||||
;; We need to create a "scope" for svg classes. The root of the imported SVG (first group) will
|
||||
;; be stored in the context. When rendering the styles we add its id as prefix.
|
||||
[svg-wrapper svg-wrapper-props]
|
||||
(if (and (contains? shape :svg-attrs) (not current-svg-root-id))
|
||||
[(mf/provider muc/current-svg-root-id) #js {:value (:id shape)}]
|
||||
[mf/Fragment #js {}])]
|
||||
|
||||
;; We need to separate mask and clip into two because a bug in
|
||||
;; Firefox breaks when the group has clip+mask+foreignObject
|
||||
;; Clip and mask separated will work in every platform Firefox
|
||||
;; bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1734805
|
||||
[:> wrapper clip-props
|
||||
[:> wrapper mask-props
|
||||
(when ^boolean masked-group?
|
||||
[:& render-mask {:mask mask}])
|
||||
[:> svg-wrapper svg-wrapper-props
|
||||
[:> wrapper clip-props
|
||||
[:> wrapper mask-props
|
||||
(when ^boolean masked-group?
|
||||
[:& render-mask {:mask mask}])
|
||||
|
||||
(for [item childs]
|
||||
[:& shape-wrapper
|
||||
{:shape item
|
||||
:key (dm/str (dm/get-prop item :id))}])]]))))
|
||||
(for [item childs]
|
||||
[:& shape-wrapper
|
||||
{:shape item
|
||||
:key (dm/str (dm/get-prop item :id))}])]]]))))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -104,9 +104,20 @@
|
|||
svg-root? (and (map? content) (= tag :svg))
|
||||
svg-tag? (map? content)
|
||||
svg-leaf? (string? content)
|
||||
valid-tag? (contains? csvg/svg-tags tag)]
|
||||
valid-tag? (contains? csvg/svg-tags tag)
|
||||
|
||||
current-svg-root-id (mf/use-ctx muc/current-svg-root-id)
|
||||
|
||||
;; We need to create a "scope" for svg classes. The root of the imported SVG (first group) will
|
||||
;; be stored in the context and with this we scoped the styles:
|
||||
style-content
|
||||
(when (= tag :style)
|
||||
(dm/str "#shape-" current-svg-root-id "{ " (->> shape :content :content (str/join "\n")) " }"))]
|
||||
|
||||
(cond
|
||||
(= tag :style)
|
||||
[:style style-content]
|
||||
|
||||
^boolean svg-root?
|
||||
[:& svg-root {:shape shape}
|
||||
(for [item childs]
|
||||
|
|
|
@ -54,13 +54,7 @@
|
|||
get-sorted-colors
|
||||
(mf/use-fn
|
||||
(fn [colors]
|
||||
(sort (fn [a b]
|
||||
(let [[ah _ al] (c/hex->hsl (:color a))
|
||||
[bh _ bl] (c/hex->hsl (:color b))
|
||||
a (+ (* ah 100) (* al 99))
|
||||
b (+ (* bh 100) (* bl 99))]
|
||||
(compare a b)))
|
||||
(into [] (filter check-valid-color?) colors))))
|
||||
(sort c/sort-colors (into [] (filter check-valid-color?) colors))))
|
||||
|
||||
toggle-palette
|
||||
(mf/use-fn
|
||||
|
|
|
@ -101,6 +101,7 @@
|
|||
(fn []
|
||||
(->> (http/send! {:method :get
|
||||
:uri plugin-url
|
||||
:omit-default-headers true
|
||||
:response-type :json})
|
||||
(rx/map :body)
|
||||
(rx/subs!
|
||||
|
|
|
@ -32,12 +32,6 @@
|
|||
;;
|
||||
;; PLUGINS PUBLIC API - The plugins will able to access this functions
|
||||
;;
|
||||
(def ^:private
|
||||
xf-map-shape-proxy
|
||||
(comp
|
||||
(map val)
|
||||
(map shape/data->shape-proxy)))
|
||||
|
||||
(defn create-shape
|
||||
[type]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
|
@ -50,7 +44,7 @@
|
|||
(cb/with-objects (:objects page))
|
||||
(cb/add-object shape))]
|
||||
(st/emit! (ch/commit-changes changes))
|
||||
(shape/data->shape-proxy shape)))
|
||||
(shape/shape-proxy (:id shape))))
|
||||
|
||||
(deftype PenpotContext []
|
||||
Object
|
||||
|
@ -64,13 +58,13 @@
|
|||
|
||||
(getFile
|
||||
[_]
|
||||
(file/data->file-proxy (:workspace-file @st/state) (:workspace-data @st/state)))
|
||||
(file/file-proxy (:current-file-id @st/state)))
|
||||
|
||||
(getPage
|
||||
[_]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
page (dm/get-in @st/state [:workspace-data :pages-index page-id])]
|
||||
(page/data->page-proxy page)))
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
page-id (:current-page-id @st/state)]
|
||||
(page/page-proxy file-id page-id)))
|
||||
|
||||
(getSelected
|
||||
[_]
|
||||
|
@ -79,17 +73,12 @@
|
|||
|
||||
(getSelectedShapes
|
||||
[_]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
selection (get-in @st/state [:workspace-local :selected])
|
||||
objects (dm/get-in @st/state [:workspace-data :pages-index page-id :objects])
|
||||
shapes (select-keys objects selection)]
|
||||
(apply array (sequence xf-map-shape-proxy shapes))))
|
||||
(let [selection (get-in @st/state [:workspace-local :selected])]
|
||||
(apply array (sequence (map shape/shape-proxy) selection))))
|
||||
|
||||
(getRoot
|
||||
[_]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
root (dm/get-in @st/state [:workspace-data :pages-index page-id :objects uuid/zero])]
|
||||
(shape/data->shape-proxy root)))
|
||||
(shape/shape-proxy uuid/zero))
|
||||
|
||||
(getTheme
|
||||
[_]
|
||||
|
@ -100,7 +89,7 @@
|
|||
|
||||
(uploadMediaUrl
|
||||
[_ name url]
|
||||
(let [file-id (get-in @st/state [:workspace-file :id])]
|
||||
(let [file-id (:current-file-id @st/state)]
|
||||
(p/create
|
||||
(fn [resolve reject]
|
||||
(->> (dwm/upload-media-url name file-id url)
|
||||
|
@ -110,17 +99,17 @@
|
|||
|
||||
(group
|
||||
[_ shapes]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
page-id (:current-page-id @st/state)
|
||||
id (uuid/next)
|
||||
ids (into #{} (map #(get (obj/get % "_data") :id)) shapes)]
|
||||
ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dwg/group-shapes id ids))
|
||||
(shape/data->shape-proxy
|
||||
(dm/get-in @st/state [:workspace-data :pages-index page-id :objects id]))))
|
||||
(shape/shape-proxy file-id page-id id)))
|
||||
|
||||
(ungroup
|
||||
[_ group & rest]
|
||||
(let [shapes (concat [group] rest)
|
||||
ids (into #{} (map #(get (obj/get % "_data") :id)) shapes)]
|
||||
ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dwg/ungroup-shapes ids))))
|
||||
|
||||
(createFrame
|
||||
|
@ -133,7 +122,8 @@
|
|||
|
||||
(createText
|
||||
[_ text]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
page-id (:current-page-id @st/state)
|
||||
page (dm/get-in @st/state [:workspace-data :pages-index page-id])
|
||||
shape (-> (cts/setup-shape {:type :text :x 0 :y 0 :grow-type :auto-width})
|
||||
(txt/change-text text)
|
||||
|
@ -144,23 +134,24 @@
|
|||
(cb/with-objects (:objects page))
|
||||
(cb/add-object shape))]
|
||||
(st/emit! (ch/commit-changes changes))
|
||||
(shape/data->shape-proxy shape)))
|
||||
(shape/shape-proxy file-id page-id (:id shape))))
|
||||
|
||||
(createShapeFromSvg
|
||||
[_ svg-string]
|
||||
(when (some? svg-string)
|
||||
(let [id (uuid/next)
|
||||
file-id (:current-file-id @st/state)
|
||||
page-id (:current-page-id @st/state)]
|
||||
(st/emit! (dwm/create-svg-shape id "svg" svg-string (gpt/point 0 0)))
|
||||
(shape/data->shape-proxy
|
||||
(dm/get-in @st/state [:workspace-data :pages-index page-id :objects id]))))))
|
||||
(shape/shape-proxy file-id page-id id)))))
|
||||
|
||||
(defn create-context
|
||||
[]
|
||||
(cr/add-properties!
|
||||
(PenpotContext.)
|
||||
{:name "root" :get #(.getRoot ^js %)}
|
||||
{:name "currentFile" :get #(.getFile ^js %)}
|
||||
{:name "currentPage" :get #(.getPage ^js %)}
|
||||
{:name "selection" :get #(.getSelectedShapes ^js %)}
|
||||
{:name "viewport" :get #(.getViewport ^js %)}
|
||||
{:name "library" :get (fn [_] (library/create-library-subcontext))}))
|
||||
{:name "library" :get (fn [_] (library/library-subcontext))}))
|
||||
|
|
|
@ -23,17 +23,18 @@
|
|||
(if (and (identical? old-file new-file)
|
||||
(identical? old-data new-data))
|
||||
::not-changed
|
||||
(file/data->file-proxy new-file new-data))))
|
||||
(file/file-proxy (:id new-file)))))
|
||||
|
||||
(defmethod handle-state-change "pagechange"
|
||||
[_ old-val new-val]
|
||||
(let [old-page-id (:current-page-id old-val)
|
||||
(let [file-id (:current-file-id new-val)
|
||||
old-page-id (:current-page-id old-val)
|
||||
new-page-id (:current-page-id new-val)
|
||||
old-page (dm/get-in old-val [:workspace-data :pages-index old-page-id])
|
||||
new-page (dm/get-in new-val [:workspace-data :pages-index new-page-id])]
|
||||
(if (identical? old-page new-page)
|
||||
::not-changed
|
||||
(page/data->page-proxy new-page))))
|
||||
(page/page-proxy file-id new-page-id))))
|
||||
|
||||
(defmethod handle-state-change "selectionchange"
|
||||
[_ old-val new-val]
|
||||
|
|
|
@ -7,38 +7,34 @@
|
|||
(ns app.plugins.file
|
||||
"RPC for plugins runtime."
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.record :as crc]
|
||||
[app.plugins.page :as page]
|
||||
[app.plugins.utils :refer [get-data-fn]]))
|
||||
[app.plugins.utils :refer [locate-file proxy->file]]
|
||||
[app.util.object :as obj]))
|
||||
|
||||
(def ^:private
|
||||
xf-map-page-proxy
|
||||
(comp
|
||||
(map val)
|
||||
(map page/data->page-proxy)))
|
||||
|
||||
(deftype FileProxy [#_:clj-kondo/ignore _data]
|
||||
(deftype FileProxy [$id]
|
||||
Object
|
||||
(getPages [_]
|
||||
;; Returns a lazy (iterable) of all available pages
|
||||
(apply array (sequence xf-map-page-proxy (:pages-index _data)))))
|
||||
(let [file (locate-file $id)]
|
||||
(apply array (sequence (map #(page/page-proxy $id %)) (dm/get-in file [:data :pages]))))))
|
||||
|
||||
(crc/define-properties!
|
||||
FileProxy
|
||||
{:name js/Symbol.toStringTag
|
||||
:get (fn [] (str "FileProxy"))})
|
||||
|
||||
(defn data->file-proxy
|
||||
[file data]
|
||||
(defn file-proxy
|
||||
[id]
|
||||
(crc/add-properties!
|
||||
(FileProxy. (merge file data))
|
||||
{:name "_data" :enumerable false}
|
||||
(FileProxy. id)
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
|
||||
{:name "id"
|
||||
:get (get-data-fn :id str)}
|
||||
:get #(dm/str (obj/get % "$id"))}
|
||||
|
||||
{:name "name"
|
||||
:get (get-data-fn :name)}
|
||||
:get #(-> % proxy->file :name)}
|
||||
|
||||
{:name "pages"
|
||||
:get #(.getPages ^js %)}))
|
||||
|
|
282
frontend/src/app/plugins/flex.cljs
Normal file
282
frontend/src/app/plugins/flex.cljs
Normal file
|
@ -0,0 +1,282 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.plugins.flex
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.record :as crc]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.main.data.workspace.shape-layout :as dwsl]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.utils :as utils :refer [proxy->shape]]
|
||||
[app.util.object :as obj]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(deftype FlexLayout [$file $page $id]
|
||||
Object
|
||||
(remove
|
||||
[_]
|
||||
(st/emit! (dwsl/remove-layout #{$id})))
|
||||
|
||||
(appendChild
|
||||
[_ child]
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (dwt/move-shapes-to-frame #{child-id} $id nil nil)
|
||||
(ptk/data-event :layout/update {:ids [$id]})))))
|
||||
|
||||
(defn flex-layout-proxy
|
||||
[file-id page-id id]
|
||||
(-> (FlexLayout. file-id page-id id)
|
||||
(crc/add-properties!
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "$page" :enumerable false :get (constantly page-id)}
|
||||
|
||||
{:name "dir"
|
||||
:get #(-> % proxy->shape :layout-flex-dir d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/flex-direction-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-flex-dir value})))))}
|
||||
|
||||
{:name "alignItems"
|
||||
:get #(-> % proxy->shape :layout-align-items d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/align-items-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-items value})))))}
|
||||
|
||||
{:name "alignContent"
|
||||
:get #(-> % proxy->shape :layout-align-content d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/align-content-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-content value})))))}
|
||||
|
||||
{:name "justifyItems"
|
||||
:get #(-> % proxy->shape :layout-justify-items d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/justify-items-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-items value})))))}
|
||||
|
||||
{:name "justifyContent"
|
||||
:get #(-> % proxy->shape :layout-justify-content d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/justify-content-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-content value})))))}
|
||||
|
||||
{:name "rowGap"
|
||||
:get #(-> % proxy->shape :layout-gap :row-gap)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:row-gap value}})))))}
|
||||
|
||||
{:name "columnGap"
|
||||
:get #(-> % proxy->shape :layout-gap :column-gap)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:column-gap value}})))))}
|
||||
|
||||
{:name "verticalPadding"
|
||||
:get #(-> % proxy->shape :layout-padding :p1)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value :p3 value}})))))}
|
||||
|
||||
{:name "horizontalPadding"
|
||||
:get #(-> % proxy->shape :layout-padding :p2)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value :p4 value}})))))}
|
||||
|
||||
|
||||
{:name "topPadding"
|
||||
:get #(-> % proxy->shape :layout-padding :p1)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value}})))))}
|
||||
|
||||
{:name "rightPadding"
|
||||
:get #(-> % proxy->shape :layout-padding :p2)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value}})))))}
|
||||
|
||||
{:name "bottomPadding"
|
||||
:get #(-> % proxy->shape :layout-padding :p3)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p3 value}})))))}
|
||||
|
||||
{:name "leftPadding"
|
||||
:get #(-> % proxy->shape :layout-padding :p4)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p4 value}})))))})))
|
||||
|
||||
|
||||
(deftype LayoutChildProxy [$file $page $id])
|
||||
|
||||
(defn layout-child-proxy
|
||||
[file-id page-id id]
|
||||
(-> (LayoutChildProxy. file-id page-id id)
|
||||
(crc/add-properties!
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "$page" :enumerable false :get (constantly page-id)}
|
||||
|
||||
{:name "absolute"
|
||||
:get #(-> % proxy->shape :layout-item-absolute boolean)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (boolean? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-item-absolute value})))))}
|
||||
|
||||
{:name "zIndex"
|
||||
:get #(-> % proxy->shape :layout-item-z-index (d/nilv 0))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-z-index value})))))}
|
||||
|
||||
{:name "horizontalSizing"
|
||||
:get #(-> % proxy->shape :layout-item-h-sizing (d/nilv :fix) d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/item-h-sizing-types value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-h-sizing value})))))}
|
||||
|
||||
{:name "verticalSizing"
|
||||
:get #(-> % proxy->shape :layout-item-v-sizing (d/nilv :fix) d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/item-v-sizing-types value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-v-sizing value})))))}
|
||||
|
||||
{:name "alignSelf"
|
||||
:get #(-> % proxy->shape :layout-item-align-self (d/nilv :auto) d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/item-align-self-types value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-align-self value})))))}
|
||||
|
||||
{:name "verticalMargin"
|
||||
:get #(-> % proxy->shape :layout-item-margin :m1 (d/nilv 0))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m1 value :m3 value}})))))}
|
||||
|
||||
{:name "horizontalMargin"
|
||||
:get #(-> % proxy->shape :layout-item-margin :m2 (d/nilv 0))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m2 value :m4 value}})))))}
|
||||
|
||||
{:name "topMargin"
|
||||
:get #(-> % proxy->shape :layout-item-margin :m1 (d/nilv 0))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m1 value}})))))}
|
||||
|
||||
{:name "rightMargin"
|
||||
:get #(-> % proxy->shape :layout-item-margin :m2 (d/nilv 0))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m2 value}})))))}
|
||||
|
||||
{:name "bottomMargin"
|
||||
:get #(-> % proxy->shape :layout-item-margin :m3 (d/nilv 0))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m3 value}})))))}
|
||||
|
||||
{:name "leftMargin"
|
||||
:get #(-> % proxy->shape :layout-item-margin :m4 (d/nilv 0))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m4 value}})))))}
|
||||
|
||||
{:name "maxWidth"
|
||||
:get #(-> % proxy->shape :layout-item-max-w)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-max-w value})))))}
|
||||
|
||||
{:name "minWidth"
|
||||
:get #(-> % proxy->shape :layout-item-min-w)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-min-w value})))))}
|
||||
|
||||
{:name "maxHeight"
|
||||
:get #(-> % proxy->shape :layout-item-max-h)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-max-h value})))))}
|
||||
|
||||
{:name "minHeight"
|
||||
:get #(-> % proxy->shape :layout-item-min-h)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-number? value)
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-min-h value})))))})))
|
|
@ -10,11 +10,10 @@
|
|||
[app.common.record :as crc]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.shape-layout :as dwsl]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.utils :as utils :refer [get-data get-state]]
|
||||
[app.plugins.utils :as utils :refer [proxy->shape locate-shape]]
|
||||
[app.util.object :as obj]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
|
@ -24,183 +23,266 @@
|
|||
js/Object
|
||||
(apply array (->> tracks (map utils/to-js)))))
|
||||
|
||||
(deftype GridLayout [_data]
|
||||
(deftype GridLayout [$file $page $id]
|
||||
Object
|
||||
|
||||
(addRow
|
||||
[self type value]
|
||||
(let [id (get-data self :id)
|
||||
type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{id} :row {:type type :value value}))))
|
||||
[_ type value]
|
||||
(let [type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :row {:type type :value value}))))
|
||||
|
||||
(addRowAtIndex
|
||||
[self index type value]
|
||||
(let [id (get-data self :id)
|
||||
type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{id} :row {:type type :value value} index))))
|
||||
[_ index type value]
|
||||
(let [type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :row {:type type :value value} index))))
|
||||
|
||||
(addColumn
|
||||
[self type value]
|
||||
(let [id (get-data self :id)
|
||||
type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{id} :column {:type type :value value}))))
|
||||
[_ type value]
|
||||
(let [type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :column {:type type :value value}))))
|
||||
|
||||
(addColumnAtIndex
|
||||
[self index type value]
|
||||
(let [id (get-data self :id)
|
||||
type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{id} :column {:type type :value value} index))))
|
||||
[_ index type value]
|
||||
(let [type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :column {:type type :value value} index))))
|
||||
|
||||
(removeRow
|
||||
[self index]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwsl/remove-layout-track #{id} :row index))))
|
||||
[_ index]
|
||||
(st/emit! (dwsl/remove-layout-track #{$id} :row index)))
|
||||
|
||||
(removeColumn
|
||||
[self index]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwsl/remove-layout-track #{id} :column index))))
|
||||
[_ index]
|
||||
(st/emit! (dwsl/remove-layout-track #{$id} :column index)))
|
||||
|
||||
(setColumn
|
||||
[self index type value]
|
||||
(let [id (get-data self :id)
|
||||
type (keyword type)]
|
||||
(st/emit! (dwsl/change-layout-track #{id} :column index (d/without-nils {:type type :value value})))))
|
||||
[_ index type value]
|
||||
(let [type (keyword type)]
|
||||
(st/emit! (dwsl/change-layout-track #{$id} :column index (d/without-nils {:type type :value value})))))
|
||||
|
||||
(setRow
|
||||
[self index type value]
|
||||
(let [id (get-data self :id)
|
||||
type (keyword type)]
|
||||
(st/emit! (dwsl/change-layout-track #{id} :row index (d/without-nils {:type type :value value})))))
|
||||
[_ index type value]
|
||||
(let [type (keyword type)]
|
||||
(st/emit! (dwsl/change-layout-track #{$id} :row index (d/without-nils {:type type :value value})))))
|
||||
|
||||
(remove
|
||||
[self]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwsl/remove-layout #{id}))))
|
||||
[_]
|
||||
(st/emit! (dwsl/remove-layout #{$id})))
|
||||
|
||||
(appendChild
|
||||
[self child row column]
|
||||
(let [parent-id (get-data self :id)
|
||||
child-id (uuid/uuid (obj/get child "id"))]
|
||||
(st/emit! (dwt/move-shapes-to-frame #{child-id} parent-id nil [row column])
|
||||
(ptk/data-event :layout/update {:ids [parent-id]})))))
|
||||
[_ child row column]
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (dwt/move-shapes-to-frame #{child-id} $id nil [row column])
|
||||
(ptk/data-event :layout/update {:ids [$id]})))))
|
||||
|
||||
(defn grid-layout-proxy
|
||||
[data]
|
||||
(-> (GridLayout. data)
|
||||
[file-id page-id id]
|
||||
(-> (GridLayout. file-id page-id id)
|
||||
(crc/add-properties!
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "$page" :enumerable false :get (constantly page-id)}
|
||||
{:name "dir"
|
||||
:get #(get-state % :layout-grid-dir d/name)
|
||||
:get #(-> % proxy->shape :layout-grid-dir d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/grid-direction-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-grid-dir value})))))}
|
||||
|
||||
{:name "rows"
|
||||
:get #(get-state % :layout-grid-rows make-tracks)}
|
||||
:get #(-> % proxy->shape :layout-grid-rows make-tracks)}
|
||||
|
||||
{:name "columns"
|
||||
:get #(get-state % :layout-grid-columns make-tracks)}
|
||||
:get #(-> % proxy->shape :layout-grid-columns make-tracks)}
|
||||
|
||||
{:name "alignItems"
|
||||
:get #(get-state % :layout-align-items d/name)
|
||||
:get #(-> % proxy->shape :layout-align-items d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/align-items-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-items value})))))}
|
||||
|
||||
{:name "alignContent"
|
||||
:get #(get-state % :layout-align-content d/name)
|
||||
:get #(-> % proxy->shape :layout-align-content d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/align-content-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-content value})))))}
|
||||
|
||||
{:name "justifyItems"
|
||||
:get #(get-state % :layout-justify-items d/name)
|
||||
:get #(-> % proxy->shape :layout-justify-items d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/justify-items-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-items value})))))}
|
||||
|
||||
{:name "justifyContent"
|
||||
:get #(get-state % :layout-justify-content d/name)
|
||||
:get #(-> % proxy->shape :layout-justify-content d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/justify-content-types value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-content value})))))}
|
||||
|
||||
{:name "rowGap"
|
||||
:get #(:row-gap (get-state % :layout-gap))
|
||||
:get #(-> % proxy->shape :layout-gap :row-gap)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:row-gap value}})))))}
|
||||
|
||||
{:name "columnGap"
|
||||
:get #(:column-gap (get-state % :layout-gap))
|
||||
:get #(-> % proxy->shape :layout-gap :column-gap)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:column-gap value}})))))}
|
||||
|
||||
{:name "verticalPadding"
|
||||
:get #(:p1 (get-state % :layout-padding))
|
||||
:get #(-> % proxy->shape :layout-padding :p1)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value :p3 value}})))))}
|
||||
|
||||
{:name "horizontalPadding"
|
||||
:get #(:p2 (get-state % :layout-padding))
|
||||
:get #(-> % proxy->shape :layout-padding :p2)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value :p4 value}})))))}
|
||||
|
||||
|
||||
{:name "topPadding"
|
||||
:get #(:p1 (get-state % :layout-padding))
|
||||
:get #(-> % proxy->shape :layout-padding :p1)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value}})))))}
|
||||
|
||||
{:name "rightPadding"
|
||||
:get #(:p2 (get-state % :layout-padding))
|
||||
:get #(-> % proxy->shape :layout-padding :p2)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value}})))))}
|
||||
|
||||
{:name "bottomPadding"
|
||||
:get #(:p3 (get-state % :layout-padding))
|
||||
:get #(-> % proxy->shape :layout-padding :p3)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p3 value}})))))}
|
||||
|
||||
{:name "leftPadding"
|
||||
:get #(:p4 (get-state % :layout-padding))
|
||||
:get #(-> % proxy->shape :layout-padding :p4)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p4 value}})))))})))
|
||||
|
||||
(deftype GridCellProxy [$file $page $id])
|
||||
|
||||
(defn layout-cell-proxy
|
||||
[file-id page-id id]
|
||||
(letfn [(locate-cell [_]
|
||||
(let [shape (locate-shape file-id page-id id)
|
||||
parent (locate-shape file-id page-id (:parent-id shape))]
|
||||
(ctl/get-cell-by-shape-id parent id)))]
|
||||
|
||||
(-> (GridCellProxy. file-id page-id id)
|
||||
(crc/add-properties!
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "$page" :enumerable false :get (constantly page-id)}
|
||||
|
||||
{:name "row"
|
||||
:get #(-> % locate-cell :row)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
cell (locate-cell self)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:row value})))))}
|
||||
|
||||
{:name "rowSpan"
|
||||
:get #(-> % locate-cell :row-span)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
cell (locate-cell self)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:row-span value})))))}
|
||||
|
||||
{:name "column"
|
||||
:get #(-> % locate-cell :column)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
cell (locate-cell self)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:column value})))))}
|
||||
|
||||
{:name "columnSpan"
|
||||
:get #(-> % locate-cell :column-span)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
cell (locate-cell self)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:column-span value})))))}
|
||||
|
||||
{:name "areaName"
|
||||
:get #(-> % locate-cell :area-name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
cell (locate-cell self)]
|
||||
(when (string? value)
|
||||
(st/emit! (dwsl/update-grid-cells (:parent-id shape) #{(:id cell)} {:area-name value})))))}
|
||||
|
||||
{:name "position"
|
||||
:get #(-> % locate-cell :position d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
cell (locate-cell self)
|
||||
value (keyword value)]
|
||||
(when (contains? ctl/grid-position-types value)
|
||||
(st/emit! (dwsl/change-cells-mode (:parent-id shape) #{(:id cell)} value)))))}
|
||||
|
||||
{:name "alignSelf"
|
||||
:get #(-> % locate-cell :align-self d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
value (keyword value)
|
||||
cell (locate-cell self)]
|
||||
(when (contains? ctl/grid-cell-align-self-types value)
|
||||
(st/emit! (dwsl/update-grid-cells (:parent-id shape) #{(:id cell)} {:align-self value})))))}
|
||||
|
||||
{:name "justifySelf"
|
||||
:get #(-> % locate-cell :justify-self d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [shape (proxy->shape self)
|
||||
value (keyword value)
|
||||
cell (locate-cell self)]
|
||||
(when (contains? ctl/grid-cell-justify-self-types value)
|
||||
(st/emit! (dwsl/update-grid-cells (:parent-id shape) #{(:id cell)} {:justify-self value})))))}))))
|
||||
|
|
|
@ -7,71 +7,135 @@
|
|||
(ns app.plugins.library
|
||||
"RPC for plugins runtime."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.record :as cr]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.utils :as utils :refer [get-data]]
|
||||
[app.util.object :as obj]))
|
||||
[app.plugins.utils :as u]))
|
||||
|
||||
(defn get-library-info
|
||||
([self attr]
|
||||
(let [lib-id (get-data self :id)
|
||||
current-file-id (:current-file-id @st/state)]
|
||||
(if (= lib-id current-file-id)
|
||||
(dm/get-in @st/state [:workspace-file attr])
|
||||
(dm/get-in @st/state [:workspace-libraries lib-id attr]))))
|
||||
(deftype LibraryColorProxy [$file $id]
|
||||
Object
|
||||
|
||||
([self attr mapfn]
|
||||
(-> (get-library-info self attr)
|
||||
(mapfn))))
|
||||
(asFill [_]
|
||||
(let [color (u/locate-library-color $file $id)]
|
||||
(u/to-js
|
||||
(d/without-nils
|
||||
{:fill-color (:color color)
|
||||
:fill-opacity (:opacity color)
|
||||
:fill-color-gradient (:gradient color)
|
||||
:fill-color-ref-file $file
|
||||
:fill-color-ref-id $id
|
||||
:fill-image (:image color)}))))
|
||||
|
||||
(defn get-library-data
|
||||
([self attr]
|
||||
(let [lib-id (get-data self :id)
|
||||
current-file-id (:current-file-id @st/state)]
|
||||
(if (= lib-id current-file-id)
|
||||
(dm/get-in @st/state [:workspace-data attr])
|
||||
(dm/get-in @st/state [:workspace-libraries lib-id :data attr]))))
|
||||
(asStroke [_]
|
||||
(let [color (u/locate-library-color $file $id)]
|
||||
(u/to-js
|
||||
(d/without-nils
|
||||
{:stroke-color (:color color)
|
||||
:stroke-opacity (:opacity color)
|
||||
:stroke-color-gradient (:gradient color)
|
||||
:stroke-color-ref-file $file
|
||||
:stroke-color-ref-id $id
|
||||
:stroke-image (:image color)
|
||||
:stroke-style :solid
|
||||
:stroke-alignment :inner})))))
|
||||
|
||||
([self attr mapfn]
|
||||
(-> (get-library-data self attr)
|
||||
(mapfn))))
|
||||
(defn lib-color-proxy
|
||||
[file-id id]
|
||||
(assert (uuid? file-id))
|
||||
(assert (uuid? id))
|
||||
|
||||
(defn- array-to-js
|
||||
[value]
|
||||
(.freeze
|
||||
js/Object
|
||||
(apply array (->> value (map utils/to-js)))))
|
||||
|
||||
(deftype Library [_data]
|
||||
Object)
|
||||
|
||||
(defn create-library
|
||||
[data]
|
||||
(cr/add-properties!
|
||||
(Library. data)
|
||||
{:name "_data"
|
||||
:enumerable false}
|
||||
(LibraryColorProxy. file-id id)
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
|
||||
{:name "id"
|
||||
:get (fn [self]
|
||||
(str (:id (obj/get self "_data"))))}
|
||||
{:name "id" :get (fn [_] (dm/str id))}
|
||||
|
||||
{:name "name"
|
||||
:get (fn [self]
|
||||
(get-library-info self :name))}
|
||||
:get #(-> % u/proxy->library-color :name)}
|
||||
|
||||
{:name "color"
|
||||
:get #(-> % u/proxy->library-color :color)}
|
||||
|
||||
{:name "opacity"
|
||||
:get #(-> % u/proxy->library-color :opacity)}
|
||||
|
||||
{:name "gradient"
|
||||
:get #(-> % u/proxy->library-color :gradient u/to-js)}
|
||||
|
||||
{:name "image"
|
||||
:get #(-> % u/proxy->library-color :image u/to-js)}))
|
||||
|
||||
(deftype LibraryTypographyProxy [$file $id]
|
||||
Object)
|
||||
|
||||
(defn lib-typography-proxy
|
||||
[file-id id]
|
||||
(assert (uuid? file-id))
|
||||
(assert (uuid? id))
|
||||
|
||||
(cr/add-properties!
|
||||
(LibraryTypographyProxy. file-id id)
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "id" :get (fn [_] (dm/str id))}
|
||||
{:name "name"
|
||||
:get #(-> % u/proxy->library-typography :name)}))
|
||||
|
||||
(deftype LibraryComponentProxy [$file $id]
|
||||
Object)
|
||||
|
||||
(defn lib-component-proxy
|
||||
[file-id id]
|
||||
(assert (uuid? file-id))
|
||||
(assert (uuid? id))
|
||||
|
||||
(cr/add-properties!
|
||||
(LibraryComponentProxy. file-id id)
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "id" :get (fn [_] (dm/str id))}
|
||||
{:name "name"
|
||||
:get #(-> % u/proxy->library-component :name)}))
|
||||
|
||||
(deftype Library [$id]
|
||||
Object)
|
||||
|
||||
(defn library-proxy
|
||||
[file-id]
|
||||
(assert (uuid? file-id) "File id not valid")
|
||||
|
||||
(cr/add-properties!
|
||||
(Library. file-id)
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
|
||||
{:name "id"
|
||||
:get #(-> % u/proxy->file :id str)}
|
||||
|
||||
{:name "name"
|
||||
:get #(-> % u/proxy->file :name)}
|
||||
|
||||
{:name "colors"
|
||||
:get (fn [self]
|
||||
(array-to-js (get-library-data self :colors vals)))}
|
||||
:get
|
||||
(fn [_]
|
||||
(let [file (u/locate-file file-id)
|
||||
colors (->> file :data :colors keys (map #(lib-color-proxy file-id %)))]
|
||||
(apply array colors)))}
|
||||
|
||||
{:name "typographies"
|
||||
:get (fn [self]
|
||||
(array-to-js (get-library-data self :typographies vals)))}
|
||||
:get
|
||||
(fn [_]
|
||||
(let [file (u/locate-file file-id)
|
||||
typographies (->> file :data :typographies keys (map #(lib-typography-proxy file-id %)))]
|
||||
(apply array typographies)))}
|
||||
|
||||
{:name "components"
|
||||
:get (fn [self]
|
||||
(array-to-js (get-library-data self :components vals)))}))
|
||||
:get
|
||||
(fn [_]
|
||||
(let [file (u/locate-file file-id)
|
||||
components (->> file :data :componentes keys (map #(lib-component-proxy file-id %)))]
|
||||
(apply array components)))}))
|
||||
|
||||
(deftype PenpotLibrarySubcontext []
|
||||
Object
|
||||
|
@ -80,17 +144,15 @@
|
|||
|
||||
(find [_]))
|
||||
|
||||
(defn create-library-subcontext
|
||||
(defn library-subcontext
|
||||
[]
|
||||
(cr/add-properties!
|
||||
(PenpotLibrarySubcontext.)
|
||||
{:name "local" :get
|
||||
(fn [_]
|
||||
(let [file (get @st/state :workspace-file)
|
||||
data (get @st/state :workspace-data)]
|
||||
(create-library (assoc file :data data))))}
|
||||
(library-proxy (:current-file-id @st/state)))}
|
||||
|
||||
{:name "connected" :get
|
||||
(fn [_]
|
||||
(let [libraries (get @st/state :workspace-libraries)]
|
||||
(apply array (->> libraries vals (map create-library)))))}))
|
||||
(apply array (->> libraries vals (map library-proxy)))))}))
|
||||
|
|
|
@ -7,46 +7,48 @@
|
|||
(ns app.plugins.page
|
||||
"RPC for plugins runtime."
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.record :as crc]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.plugins.shape :as shape]
|
||||
[app.plugins.utils :refer [get-data-fn]]))
|
||||
[app.plugins.utils :refer [locate-page proxy->page]]
|
||||
[app.util.object :as obj]))
|
||||
|
||||
(def ^:private
|
||||
xf-map-shape-proxy
|
||||
(comp
|
||||
(map val)
|
||||
(map shape/data->shape-proxy)))
|
||||
|
||||
(deftype PageProxy [#_:clj-kondo/ignore _data]
|
||||
(deftype PageProxy [$file $id]
|
||||
Object
|
||||
(getShapeById [_ id]
|
||||
(shape/data->shape-proxy (get (:objects _data) (uuid/uuid id))))
|
||||
(getShapeById
|
||||
[_ shape-id]
|
||||
(let [shape-id (uuid/uuid shape-id)]
|
||||
(shape/shape-proxy $file $id shape-id)))
|
||||
|
||||
(getRoot [_]
|
||||
(shape/data->shape-proxy (get (:objects _data) uuid/zero)))
|
||||
(getRoot
|
||||
[_]
|
||||
(shape/shape-proxy $file $id uuid/zero))
|
||||
|
||||
(findShapes [_]
|
||||
(findShapes
|
||||
[_]
|
||||
;; Returns a lazy (iterable) of all available shapes
|
||||
(apply array (sequence xf-map-shape-proxy (:objects _data)))))
|
||||
(let [page (locate-page $file $id)]
|
||||
(apply array (sequence (map shape/shape-proxy) (keys (:objects page)))))))
|
||||
|
||||
(crc/define-properties!
|
||||
PageProxy
|
||||
{:name js/Symbol.toStringTag
|
||||
:get (fn [] (str "PageProxy"))})
|
||||
|
||||
(defn data->page-proxy
|
||||
[data]
|
||||
|
||||
(defn page-proxy
|
||||
[file-id id]
|
||||
(crc/add-properties!
|
||||
(PageProxy. data)
|
||||
{:name "_data" :enumerable false}
|
||||
(PageProxy. file-id id)
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
|
||||
{:name "id"
|
||||
:get (get-data-fn :id str)}
|
||||
:get #(dm/str (obj/get % "$id"))}
|
||||
|
||||
{:name "name"
|
||||
:get (get-data-fn :name)}
|
||||
:get #(-> % proxy->page :name)}
|
||||
|
||||
{:name "root"
|
||||
:enumerable false
|
||||
:get #(.getRoot ^js %)}))
|
||||
|
|
|
@ -8,364 +8,407 @@
|
|||
"RPC for plugins runtime."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.record :as crc]
|
||||
[app.common.spec :as us]
|
||||
[app.common.text :as txt]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.main.data.workspace :as udw]
|
||||
[app.main.data.workspace.changes :as dwc]
|
||||
[app.main.data.workspace.selection :as dws]
|
||||
[app.main.data.workspace.shape-layout :as dwsl]
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.flex :as flex]
|
||||
[app.plugins.grid :as grid]
|
||||
[app.plugins.utils :as utils :refer [get-data get-data-fn get-state]]
|
||||
[app.plugins.utils :as utils :refer [locate-objects locate-shape proxy->shape array-to-js]]
|
||||
[app.util.object :as obj]))
|
||||
|
||||
(declare data->shape-proxy)
|
||||
(declare shape-proxy)
|
||||
|
||||
(defn- array-to-js
|
||||
[value]
|
||||
(.freeze
|
||||
js/Object
|
||||
(apply array (->> value (map utils/to-js)))))
|
||||
|
||||
(defn- locate-shape
|
||||
[shape-id]
|
||||
(let [page-id (:current-page-id @st/state)]
|
||||
(dm/get-in @st/state [:workspace-data :pages-index page-id :objects shape-id])))
|
||||
|
||||
(deftype ShapeProxy [#_:clj-kondo/ignore _data]
|
||||
(deftype ShapeProxy [$file $page $id]
|
||||
Object
|
||||
(resize
|
||||
[self width height]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (udw/update-dimensions [id] :width width)
|
||||
(udw/update-dimensions [id] :height height))))
|
||||
[_ width height]
|
||||
(st/emit! (udw/update-dimensions [$id] :width width)
|
||||
(udw/update-dimensions [$id] :height height)))
|
||||
|
||||
(clone [self]
|
||||
(let [id (get-data self :id)
|
||||
page-id (:current-page-id @st/state)
|
||||
ret-v (atom nil)]
|
||||
(st/emit! (dws/duplicate-shapes #{id} :change-selection? false :return-ref ret-v))
|
||||
(let [new-id (deref ret-v)
|
||||
shape (dm/get-in @st/state [:workspace-data :pages-index page-id :objects new-id])]
|
||||
(data->shape-proxy shape))))
|
||||
(clone
|
||||
[_]
|
||||
(let [ret-v (atom nil)]
|
||||
(st/emit! (dws/duplicate-shapes #{$id} :change-selection? false :return-ref ret-v))
|
||||
(shape-proxy (deref ret-v))))
|
||||
|
||||
(remove [self]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwsh/delete-shapes #{id}))))
|
||||
(remove
|
||||
[_]
|
||||
(st/emit! (dwsh/delete-shapes #{$id})))
|
||||
|
||||
;; Only for frames + groups + booleans
|
||||
(getChildren
|
||||
[self]
|
||||
(apply array (->> (get-state self :shapes)
|
||||
(map locate-shape)
|
||||
(map data->shape-proxy))))
|
||||
[_]
|
||||
(apply array (->> (locate-shape $file $page $id)
|
||||
:shapes
|
||||
(map #(shape-proxy $file $page %)))))
|
||||
|
||||
(appendChild [self child]
|
||||
(let [parent-id (get-data self :id)
|
||||
child-id (uuid/uuid (obj/get child "id"))]
|
||||
(st/emit! (udw/relocate-shapes #{child-id} parent-id 0))))
|
||||
(appendChild
|
||||
[_ child]
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (udw/relocate-shapes #{child-id} $id 0))))
|
||||
|
||||
(insertChild [self index child]
|
||||
(let [parent-id (get-data self :id)
|
||||
child-id (uuid/uuid (obj/get child "id"))]
|
||||
(st/emit! (udw/relocate-shapes #{child-id} parent-id index))))
|
||||
(insertChild
|
||||
[_ index child]
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (udw/relocate-shapes #{child-id} $id index))))
|
||||
|
||||
;; Only for frames
|
||||
(addFlexLayout [self]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwsl/create-layout-from-id id :flex :from-frame? true :calculate-params? false))))
|
||||
(addFlexLayout
|
||||
[_]
|
||||
(st/emit! (dwsl/create-layout-from-id $id :flex :from-frame? true :calculate-params? false))
|
||||
(grid/grid-layout-proxy $file $page $id))
|
||||
|
||||
(addGridLayout [self]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwsl/create-layout-from-id id :grid :from-frame? true :calculate-params? false))
|
||||
(grid/grid-layout-proxy (obj/get self "_data")))))
|
||||
(addGridLayout
|
||||
[_]
|
||||
(st/emit! (dwsl/create-layout-from-id $id :grid :from-frame? true :calculate-params? false))
|
||||
(grid/grid-layout-proxy $file $page $id)))
|
||||
|
||||
(crc/define-properties!
|
||||
ShapeProxy
|
||||
{:name js/Symbol.toStringTag
|
||||
:get (fn [] (str "ShapeProxy"))})
|
||||
|
||||
(defn data->shape-proxy
|
||||
[data]
|
||||
(defn shape-proxy
|
||||
([id]
|
||||
(shape-proxy (:current-file-id @st/state) (:current-page-id @st/state) id))
|
||||
|
||||
(-> (ShapeProxy. data)
|
||||
(crc/add-properties!
|
||||
{:name "_data"
|
||||
:enumerable false}
|
||||
([page-id id]
|
||||
(shape-proxy (:current-file-id @st/state) page-id id))
|
||||
|
||||
{:name "id"
|
||||
:get (get-data-fn :id str)}
|
||||
([file-id page-id id]
|
||||
(assert (uuid? file-id))
|
||||
(assert (uuid? page-id))
|
||||
(assert (uuid? id))
|
||||
|
||||
{:name "type"
|
||||
:get (get-data-fn :type name)}
|
||||
(let [data (locate-shape file-id page-id id)]
|
||||
(-> (ShapeProxy. file-id page-id id)
|
||||
(crc/add-properties!
|
||||
{:name "$id" :enumerable false :get (constantly id)}
|
||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||
{:name "$page" :enumerable false :get (constantly page-id)}
|
||||
|
||||
{:name "name"
|
||||
:get #(get-state % :name)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :name value)))))}
|
||||
{:name "id"
|
||||
:get #(-> % proxy->shape :id str)}
|
||||
|
||||
{:name "blocked"
|
||||
:get #(get-state % :blocked boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :blocked value)))))}
|
||||
{:name "type"
|
||||
:get #(-> % proxy->shape :type name)}
|
||||
|
||||
{:name "hidden"
|
||||
:get #(get-state % :hidden boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :hidden value)))))}
|
||||
{:name "name"
|
||||
:get #(-> % proxy->shape :name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :name value)))))}
|
||||
|
||||
{:name "proportionLock"
|
||||
:get #(get-state % :proportion-lock boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :proportion-lock value)))))}
|
||||
{:name "blocked"
|
||||
:get #(-> % proxy->shape :blocked boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :blocked value)))))}
|
||||
|
||||
{:name "constraintsHorizontal"
|
||||
:get #(get-state % :constraints-h d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (keyword value)]
|
||||
(when (contains? cts/horizontal-constraint-types value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :constraints-h value))))))}
|
||||
{:name "hidden"
|
||||
:get #(-> % proxy->shape :hidden boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :hidden value)))))}
|
||||
|
||||
{:name "constraintsVertical"
|
||||
:get #(get-state % :constraints-v d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (keyword value)]
|
||||
(when (contains? cts/vertical-constraint-types value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :constraints-v value))))))}
|
||||
{:name "proportionLock"
|
||||
:get #(-> % proxy->shape :proportion-lock boolean)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :proportion-lock value)))))}
|
||||
|
||||
{:name "borderRadius"
|
||||
:get #(get-state % :rx)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :rx value :ry value))))))}
|
||||
{:name "constraintsHorizontal"
|
||||
:get #(-> % proxy->shape :constraints-h d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? cts/horizontal-constraint-types value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :constraints-h value))))))}
|
||||
|
||||
{:name "borderRadiusTopLeft"
|
||||
:get #(get-state % :r1)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r1 value))))))}
|
||||
{:name "constraintsVertical"
|
||||
:get #(-> % proxy->shape :constraints-v d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? cts/vertical-constraint-types value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :constraints-v value))))))}
|
||||
|
||||
{:name "borderRadiusTopRight"
|
||||
:get #(get-state % :r2)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r2 value))))))}
|
||||
{:name "borderRadius"
|
||||
:get #(-> % proxy->shape :rx)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :rx value :ry value))))))}
|
||||
|
||||
{:name "borderRadiusBottomRight"
|
||||
:get #(get-state % :r3)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r3 value))))))}
|
||||
{:name "borderRadiusTopLeft"
|
||||
:get #(-> % proxy->shape :r1)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r1 value))))))}
|
||||
|
||||
{:name "borderRadiusBottomLeft"
|
||||
:get #(get-state % :r4)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r4 value))))))}
|
||||
{:name "borderRadiusTopRight"
|
||||
:get #(-> % proxy->shape :r2)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r2 value))))))}
|
||||
|
||||
{:name "opacity"
|
||||
:get #(get-state % :opacity)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(when (and (us/safe-number? value) (>= value 0) (<= value 1))
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :opacity value))))))}
|
||||
{:name "borderRadiusBottomRight"
|
||||
:get #(-> % proxy->shape :r3)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r3 value))))))}
|
||||
|
||||
{:name "blendMode"
|
||||
:get #(get-state % :blend-mode d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (keyword value)]
|
||||
(when (contains? cts/blend-modes value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :blend-mode value))))))}
|
||||
{:name "borderRadiusBottomLeft"
|
||||
:get #(-> % proxy->shape :r4)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (us/safe-int? value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :r4 value))))))}
|
||||
|
||||
{:name "shadows"
|
||||
:get #(get-state % :shadow array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :shadows value)))))}
|
||||
{:name "opacity"
|
||||
:get #(-> % proxy->shape :opacity)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (and (us/safe-number? value) (>= value 0) (<= value 1))
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :opacity value))))))}
|
||||
|
||||
{:name "blur"
|
||||
:get #(get-state % :blur utils/to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (utils/from-js value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :blur value)))))}
|
||||
{:name "blendMode"
|
||||
:get #(-> % proxy->shape :blend-mode (d/nilv :normal) d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? cts/blend-modes value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :blend-mode value))))))}
|
||||
|
||||
{:name "exports"
|
||||
:get #(get-state % :exports array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :exports value)))))}
|
||||
{:name "shadows"
|
||||
:get #(-> % proxy->shape :shadow array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :shadows value)))))}
|
||||
|
||||
;; Geometry properties
|
||||
{:name "x"
|
||||
:get #(get-state % :x)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (udw/update-position id {:x value}))))}
|
||||
{:name "blur"
|
||||
:get #(-> % proxy->shape :blur utils/to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (utils/from-js value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :blur value)))))}
|
||||
|
||||
{:name "y"
|
||||
:get #(get-state % :y)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (udw/update-position id {:y value}))))}
|
||||
{:name "exports"
|
||||
:get #(-> % proxy->shape :exports array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :exports value)))))}
|
||||
|
||||
{:name "parentX"
|
||||
:get (fn [self]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
parent-id (get-state self :parent-id)
|
||||
parent-x (dm/get-in @st/state [:workspace-data :pages-index page-id :objects parent-id :x])]
|
||||
(- (get-state self :x) parent-x)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
id (get-data self :id)
|
||||
parent-id (get-state self :parent-id)
|
||||
parent-x (dm/get-in @st/state [:workspace-data :pages-index page-id :objects parent-id :x])]
|
||||
(st/emit! (udw/update-position id {:x (+ parent-x value)}))))}
|
||||
;; Geometry properties
|
||||
{:name "x"
|
||||
:get #(-> % proxy->shape :x)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (udw/update-position id {:x value}))))}
|
||||
|
||||
{:name "parentY"
|
||||
:get (fn [self]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
parent-id (get-state self :parent-id)
|
||||
parent-y (dm/get-in @st/state [:workspace-data :pages-index page-id :objects parent-id :y])]
|
||||
(- (get-state self :y) parent-y)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
id (get-data self :id)
|
||||
parent-id (get-state self :parent-id)
|
||||
parent-y (dm/get-in @st/state [:workspace-data :pages-index page-id :objects parent-id :y])]
|
||||
(st/emit! (udw/update-position id {:y (+ parent-y value)}))))}
|
||||
{:name "y"
|
||||
:get #(-> % proxy->shape :y)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (udw/update-position id {:y value}))))}
|
||||
|
||||
{:name "frameX"
|
||||
:get (fn [self]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
frame-id (get-state self :frame-id)
|
||||
frame-x (dm/get-in @st/state [:workspace-data :pages-index page-id :objects frame-id :x])]
|
||||
(- (get-state self :x) frame-x)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
id (get-data self :id)
|
||||
frame-id (get-state self :frame-id)
|
||||
frame-x (dm/get-in @st/state [:workspace-data :pages-index page-id :objects frame-id :x])]
|
||||
(st/emit! (udw/update-position id {:x (+ frame-x value)}))))}
|
||||
{:name "parentX"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
parent-id (:parent-id shape)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)]
|
||||
(- (:x shape) (:x parent))))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
parent-id (-> self proxy->shape :parent-id)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-x (:x parent)]
|
||||
(st/emit! (udw/update-position id {:x (+ parent-x value)}))))}
|
||||
|
||||
{:name "frameY"
|
||||
:get (fn [self]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
frame-id (get-state self :frame-id)
|
||||
frame-y (dm/get-in @st/state [:workspace-data :pages-index page-id :objects frame-id :y])]
|
||||
(- (get-state self :y) frame-y)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
id (get-data self :id)
|
||||
frame-id (get-state self :frame-id)
|
||||
frame-y (dm/get-in @st/state [:workspace-data :pages-index page-id :objects frame-id :y])]
|
||||
(st/emit! (udw/update-position id {:y (+ frame-y value)}))))}
|
||||
{:name "parentY"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
parent-id (:parent-id shape)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-y (:y parent)]
|
||||
(- (:y shape) parent-y)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
parent-id (-> self proxy->shape :parent-id)
|
||||
parent (locate-shape (obj/get self "$file") (obj/get self "$page") parent-id)
|
||||
parent-y (:y parent)]
|
||||
(st/emit! (udw/update-position id {:y (+ parent-y value)}))))}
|
||||
|
||||
{:name "width"
|
||||
:get #(get-state % :width)}
|
||||
{:name "frameX"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
frame-id (:parent-id shape)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-x (:x frame)]
|
||||
(- (:x shape) frame-x)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
frame-id (-> self proxy->shape :frame-id)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-x (:x frame)]
|
||||
(st/emit! (udw/update-position id {:x (+ frame-x value)}))))}
|
||||
|
||||
{:name "height"
|
||||
:get #(get-state % :height)}
|
||||
{:name "frameY"
|
||||
:get (fn [self]
|
||||
(let [shape (proxy->shape self)
|
||||
frame-id (:parent-id shape)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-y (:y frame)]
|
||||
(- (:y shape) frame-y)))
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
frame-id (-> self proxy->shape :frame-id)
|
||||
frame (locate-shape (obj/get self "$file") (obj/get self "$page") frame-id)
|
||||
frame-y (:y frame)]
|
||||
(st/emit! (udw/update-position id {:y (+ frame-y value)}))))}
|
||||
|
||||
{:name "flipX"
|
||||
:get #(get-state % :flip-x)}
|
||||
{:name "width"
|
||||
:get #(-> % proxy->shape :width)}
|
||||
|
||||
{:name "flipY"
|
||||
:get #(get-state % :flip-y)}
|
||||
{:name "height"
|
||||
:get #(-> % proxy->shape :height)}
|
||||
|
||||
;; Strokes and fills
|
||||
{:name "fills"
|
||||
:get #(get-state % :fills array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :fills value)))))}
|
||||
{:name "flipX"
|
||||
:get #(-> % proxy->shape :flip-x)}
|
||||
|
||||
{:name "strokes"
|
||||
:get #(get-state % :strokes array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :strokes value)))))})
|
||||
{:name "flipY"
|
||||
:get #(-> % proxy->shape :flip-y)}
|
||||
|
||||
(cond-> (or (cfh/frame-shape? data) (cfh/group-shape? data) (cfh/svg-raw-shape? data) (cfh/bool-shape? data))
|
||||
(crc/add-properties!
|
||||
{:name "children"
|
||||
:get #(.getChildren ^js %)}))
|
||||
;; Strokes and fills
|
||||
{:name "fills"
|
||||
:get #(-> % proxy->shape :fills array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :fills value)))))}
|
||||
|
||||
(cond-> (not (or (cfh/frame-shape? data) (cfh/group-shape? data) (cfh/svg-raw-shape? data) (cfh/bool-shape? data)))
|
||||
(-> (obj/unset! "appendChild")
|
||||
(obj/unset! "insertChild")
|
||||
(obj/unset! "getChildren")))
|
||||
{:name "strokes"
|
||||
:get #(-> % proxy->shape :strokes array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :strokes value)))))}
|
||||
|
||||
(cond-> (cfh/frame-shape? data)
|
||||
(-> (crc/add-properties!
|
||||
{:name "grid"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [layout (get-state self :layout)]
|
||||
(when (= :grid layout)
|
||||
(grid/grid-layout-proxy data))))}
|
||||
{:name "layoutChild"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")
|
||||
objects (locate-objects file-id page-id)]
|
||||
(when (ctl/any-layout-immediate-child-id? objects id)
|
||||
(flex/layout-child-proxy file-id page-id id))))}
|
||||
|
||||
{:name "guides"
|
||||
:get #(get-state % :grids array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :grids value)))))})
|
||||
{:name "layoutCell"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")
|
||||
objects (locate-objects file-id page-id)]
|
||||
(when (ctl/grid-layout-immediate-child-id? objects id)
|
||||
(grid/layout-cell-proxy file-id page-id id))))})
|
||||
|
||||
;; TODO: Flex properties
|
||||
#_(crc/add-properties!
|
||||
{:name "flex"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [layout (get-state self :layout)]
|
||||
(when (= :flex layout)
|
||||
(flex-layout-proxy data))))})))
|
||||
(cond-> (or (cfh/frame-shape? data) (cfh/group-shape? data) (cfh/svg-raw-shape? data) (cfh/bool-shape? data))
|
||||
(crc/add-properties!
|
||||
{:name "children"
|
||||
:enumerable false
|
||||
:get #(.getChildren ^js %)}))
|
||||
|
||||
(cond-> (not (cfh/frame-shape? data))
|
||||
(-> (obj/unset! "addGridLayout")
|
||||
(obj/unset! "addFlexLayout")))
|
||||
(cond-> (not (or (cfh/frame-shape? data) (cfh/group-shape? data) (cfh/svg-raw-shape? data) (cfh/bool-shape? data)))
|
||||
(-> (obj/unset! "appendChild")
|
||||
(obj/unset! "insertChild")
|
||||
(obj/unset! "getChildren")))
|
||||
|
||||
(cond-> (cfh/text-shape? data)
|
||||
(-> (crc/add-properties!
|
||||
{:name "characters"
|
||||
:get #(get-state % :content txt/content->text)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)]
|
||||
(st/emit! (dwc/update-shapes [id] #(txt/change-text % value)))))})
|
||||
(cond-> (cfh/frame-shape? data)
|
||||
(-> (crc/add-properties!
|
||||
{:name "grid"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [layout (-> self proxy->shape :layout)
|
||||
file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")]
|
||||
(when (= :grid layout)
|
||||
(grid/grid-layout-proxy file-id page-id id))))}
|
||||
|
||||
(crc/add-properties!
|
||||
{:name "growType"
|
||||
:get #(get-state % :grow-type d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (get-data self :id)
|
||||
value (keyword value)]
|
||||
(when (contains? #{:auto-width :auto-height :fixed} value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :grow-type value))))))})))))
|
||||
{:name "flex"
|
||||
:get
|
||||
(fn [self]
|
||||
(let [layout (-> self proxy->shape :layout)
|
||||
file-id (obj/get self "$file")
|
||||
page-id (obj/get self "$page")
|
||||
id (obj/get self "$id")]
|
||||
(when (= :flex layout)
|
||||
(flex/flex-layout-proxy file-id page-id id))))}
|
||||
|
||||
{:name "guides"
|
||||
:get #(-> % proxy->shape :grids array-to-js)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (mapv #(utils/from-js %) value)]
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :grids value)))))}
|
||||
|
||||
{:name "horizontalSizing"
|
||||
:get #(-> % proxy->shape :layout-item-h-sizing (d/nilv :fix) d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? #{:fix :auto} value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-item-h-sizing value})))))}
|
||||
|
||||
{:name "verticalSizing"
|
||||
:get #(-> % proxy->shape :layout-item-v-sizing (d/nilv :fix) d/name)
|
||||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? #{:fix :auto} value)
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-item-v-sizing value})))))})))
|
||||
|
||||
(cond-> (not (cfh/frame-shape? data))
|
||||
(-> (obj/unset! "addGridLayout")
|
||||
(obj/unset! "addFlexLayout")))
|
||||
|
||||
(cond-> (cfh/text-shape? data)
|
||||
(-> (crc/add-properties!
|
||||
{:name "characters"
|
||||
:get #(-> % proxy->shape :content txt/content->text)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwc/update-shapes [id] #(txt/change-text % value)))))})
|
||||
|
||||
(crc/add-properties!
|
||||
{:name "growType"
|
||||
:get #(-> % proxy->shape :grow-type d/name)
|
||||
:set (fn [self value]
|
||||
(let [id (obj/get self "$id")
|
||||
value (keyword value)]
|
||||
(when (contains? #{:auto-width :auto-height :fixed} value)
|
||||
(st/emit! (dwc/update-shapes [id] #(assoc % :grow-type value))))))})))))))
|
||||
|
|
|
@ -16,6 +16,79 @@
|
|||
[cuerdas.core :as str]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn locate-file
|
||||
[id]
|
||||
(assert (uuid? id) "File not valid uuid")
|
||||
(if (= id (:current-file-id @st/state))
|
||||
(-> (:workspace-file @st/state)
|
||||
(assoc :data (:workspace-data @st/state)))
|
||||
(dm/get-in @st/state [:workspace-libraries id])))
|
||||
|
||||
(defn locate-page
|
||||
[file-id id]
|
||||
(assert (uuid? id) "Page not valid uuid")
|
||||
(dm/get-in (locate-file file-id) [:data :pages-index id]))
|
||||
|
||||
(defn locate-objects
|
||||
[file-id page-id]
|
||||
(:objects (locate-page file-id page-id)))
|
||||
|
||||
(defn locate-shape
|
||||
[file-id page-id id]
|
||||
(assert (uuid? id) "Shape not valid uuid")
|
||||
(dm/get-in (locate-page file-id page-id) [:objects id]))
|
||||
|
||||
(defn locate-library-color
|
||||
[file-id id]
|
||||
(assert (uuid? id) "Color not valid uuid")
|
||||
(dm/get-in (locate-file file-id) [:data :colors id]))
|
||||
|
||||
(defn locate-library-typography
|
||||
[file-id id]
|
||||
(assert (uuid? id) "Typography not valid uuid")
|
||||
(dm/get-in (locate-file file-id) [:data :typographies id]))
|
||||
|
||||
(defn locate-library-component
|
||||
[file-id id]
|
||||
(assert (uuid? id) "Component not valid uuid")
|
||||
(dm/get-in (locate-file file-id) [:data :components id]))
|
||||
|
||||
(defn proxy->file
|
||||
[proxy]
|
||||
(let [id (obj/get proxy "$id")]
|
||||
(locate-file id)))
|
||||
|
||||
(defn proxy->page
|
||||
[proxy]
|
||||
(let [file-id (obj/get proxy "$file")
|
||||
id (obj/get proxy "$id")]
|
||||
(locate-page file-id id)))
|
||||
|
||||
(defn proxy->shape
|
||||
[proxy]
|
||||
(let [file-id (obj/get proxy "$file")
|
||||
page-id (obj/get proxy "$page")
|
||||
id (obj/get proxy "$id")]
|
||||
(locate-shape file-id page-id id)))
|
||||
|
||||
(defn proxy->library-color
|
||||
[proxy]
|
||||
(let [file-id (obj/get proxy "$file")
|
||||
id (obj/get proxy "$id")]
|
||||
(locate-library-color file-id id)))
|
||||
|
||||
(defn proxy->library-typography
|
||||
[proxy]
|
||||
(let [file-id (obj/get proxy "$file")
|
||||
id (obj/get proxy "$id")]
|
||||
(locate-library-color file-id id)))
|
||||
|
||||
(defn proxy->library-component
|
||||
[proxy]
|
||||
(let [file-id (obj/get proxy "$file")
|
||||
id (obj/get proxy "$id")]
|
||||
(locate-library-color file-id id)))
|
||||
|
||||
(defn get-data
|
||||
([self attr]
|
||||
(-> (obj/get self "_data")
|
||||
|
@ -45,37 +118,51 @@
|
|||
|
||||
(defn from-js
|
||||
"Converts the object back to js"
|
||||
([obj]
|
||||
(from-js obj identity))
|
||||
([obj vfn]
|
||||
(let [ret (js->clj obj {:keyword-fn (fn [k] (str/camel (name k)))})]
|
||||
(reduce-kv
|
||||
(fn [m k v]
|
||||
(let [k (keyword (str/kebab k))
|
||||
v (cond (map? v)
|
||||
(from-js v)
|
||||
[obj]
|
||||
(when (some? obj)
|
||||
(let [process-node
|
||||
(fn process-node [node]
|
||||
(reduce-kv
|
||||
(fn [m k v]
|
||||
(let [k (keyword (str/kebab k))
|
||||
v (cond (map? v)
|
||||
(process-node v)
|
||||
|
||||
(and (string? v) (re-matches us/uuid-rx v))
|
||||
(uuid/uuid v)
|
||||
(vector? v)
|
||||
(mapv process-node v)
|
||||
|
||||
:else (vfn k v))]
|
||||
(assoc m k v)))
|
||||
{}
|
||||
ret))))
|
||||
(and (string? v) (re-matches us/uuid-rx v))
|
||||
(uuid/uuid v)
|
||||
|
||||
(= k :type)
|
||||
(keyword v)
|
||||
|
||||
:else v)]
|
||||
(assoc m k v)))
|
||||
{}
|
||||
node))]
|
||||
(process-node (js->clj obj)))))
|
||||
|
||||
(defn to-js
|
||||
"Converts to javascript an camelize the keys"
|
||||
[obj]
|
||||
(let [result
|
||||
(reduce-kv
|
||||
(fn [m k v]
|
||||
(let [v (cond (object? v) (to-js v)
|
||||
(uuid? v) (dm/str v)
|
||||
:else v)]
|
||||
(assoc m (str/camel (name k)) v)))
|
||||
{}
|
||||
obj)]
|
||||
(clj->js result)))
|
||||
(when (some? obj)
|
||||
(let [result
|
||||
(reduce-kv
|
||||
(fn [m k v]
|
||||
(let [v (cond (object? v) (to-js v)
|
||||
(uuid? v) (dm/str v)
|
||||
:else v)]
|
||||
(assoc m (str/camel (name k)) v)))
|
||||
{}
|
||||
obj)]
|
||||
(clj->js result))))
|
||||
|
||||
(defn array-to-js
|
||||
[value]
|
||||
(.freeze
|
||||
js/Object
|
||||
(apply array (->> value (map to-js)))))
|
||||
|
||||
(defn result-p
|
||||
"Creates a pair of atom+promise. The promise will be resolved when the atom gets a value.
|
||||
|
|
91
package-lock.json
generated
91
package-lock.json
generated
|
@ -1,91 +0,0 @@
|
|||
{
|
||||
"name": "penpot",
|
||||
"version": "1.20.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "penpot",
|
||||
"version": "1.20.0",
|
||||
"license": "MPL-2.0",
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.43.1",
|
||||
"@types/node": "^20.12.7"
|
||||
}
|
||||
},
|
||||
"node_modules/@playwright/test": {
|
||||
"version": "1.43.1",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.43.1.tgz",
|
||||
"integrity": "sha512-HgtQzFgNEEo4TE22K/X7sYTYNqEMMTZmFS8kTq6m8hXj+m1D8TgwgIbumHddJa9h4yl4GkKb8/bgAl2+g7eDgA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"playwright": "1.43.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.12.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz",
|
||||
"integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~5.26.4"
|
||||
}
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright": {
|
||||
"version": "1.43.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.43.1.tgz",
|
||||
"integrity": "sha512-V7SoH0ai2kNt1Md9E3Gwas5B9m8KR2GVvwZnAI6Pg0m3sh7UvgiYhRrhsziCmqMJNouPckiOhk8T+9bSAK0VIA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"playwright-core": "1.43.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fsevents": "2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright-core": {
|
||||
"version": "1.43.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.43.1.tgz",
|
||||
"integrity": "sha512-EI36Mto2Vrx6VF7rm708qSnesVQKbxEWvPrfA1IPY6HgczBplDx7ENtx+K2n4kJ41sLLkuGfmb0ZLSSXlDhqPg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"playwright-core": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "5.26.5",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue