@pixldocs/canvas-renderer 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +53 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { forwardRef, useRef, useState, useMemo, useEffect, useCallback, useImper
|
|
|
6
6
|
import { flushSync } from "react-dom";
|
|
7
7
|
import { create } from "zustand";
|
|
8
8
|
import * as fabric from "fabric";
|
|
9
|
+
import { createClient } from "@supabase/supabase-js";
|
|
9
10
|
import { createRoot } from "react-dom/client";
|
|
10
11
|
import { jsPDF, ShadingPattern } from "jspdf";
|
|
11
12
|
import { svg2pdf } from "svg2pdf.js";
|
|
@@ -8764,6 +8765,50 @@ function applyThemeToConfig(config, themeOverrides) {
|
|
|
8764
8765
|
}
|
|
8765
8766
|
return cloned;
|
|
8766
8767
|
}
|
|
8768
|
+
const SUPABASE_URL = void 0;
|
|
8769
|
+
const SUPABASE_PUBLISHABLE_KEY = void 0;
|
|
8770
|
+
createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, {
|
|
8771
|
+
auth: {
|
|
8772
|
+
storage: localStorage,
|
|
8773
|
+
persistSession: true,
|
|
8774
|
+
autoRefreshToken: true
|
|
8775
|
+
}
|
|
8776
|
+
});
|
|
8777
|
+
function repeatablePageToSection(page) {
|
|
8778
|
+
return {
|
|
8779
|
+
id: page.id,
|
|
8780
|
+
label: page.label,
|
|
8781
|
+
description: page.description,
|
|
8782
|
+
// Place pages after sections by default; explicit order preserved.
|
|
8783
|
+
order: typeof page.order === "number" ? page.order + 1e4 : 1e4,
|
|
8784
|
+
fields: page.fields,
|
|
8785
|
+
repeatable: true,
|
|
8786
|
+
minEntries: page.minEntries,
|
|
8787
|
+
maxEntries: page.maxEntries,
|
|
8788
|
+
templateKeyPrefix: page.templateKeyPrefix,
|
|
8789
|
+
children: page.children
|
|
8790
|
+
};
|
|
8791
|
+
}
|
|
8792
|
+
function getRenderableFormSections(schema) {
|
|
8793
|
+
if (!schema) return [];
|
|
8794
|
+
const base = schema.sections ?? [];
|
|
8795
|
+
const pages = schema.repeatablePages ?? [];
|
|
8796
|
+
if (!pages.length) return base;
|
|
8797
|
+
return [...base, ...pages.map(repeatablePageToSection)];
|
|
8798
|
+
}
|
|
8799
|
+
function buildRepeatablePagesInputForApply(schema, sectionState) {
|
|
8800
|
+
var _a;
|
|
8801
|
+
if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
|
|
8802
|
+
return schema.repeatablePages.map((p) => {
|
|
8803
|
+
const entries = sectionState == null ? void 0 : sectionState[p.id];
|
|
8804
|
+
const minEntries = p.minEntries != null ? Math.max(0, p.minEntries) : 1;
|
|
8805
|
+
let entryCount;
|
|
8806
|
+
if (Array.isArray(entries)) {
|
|
8807
|
+
entryCount = minEntries === 0 ? entries.length : Math.max(1, entries.length);
|
|
8808
|
+
}
|
|
8809
|
+
return { pageId: p.id, templateKeyPrefix: p.templateKeyPrefix, entryCount };
|
|
8810
|
+
});
|
|
8811
|
+
}
|
|
8767
8812
|
function mapFormDefFieldType(t) {
|
|
8768
8813
|
if (["text", "email", "tel", "textarea", "date", "url", "number", "toggle", "color", "image"].includes(t)) return t;
|
|
8769
8814
|
if (t === "currency") return "number";
|
|
@@ -10454,7 +10499,7 @@ async function resolveTemplateData(options) {
|
|
|
10454
10499
|
};
|
|
10455
10500
|
}
|
|
10456
10501
|
async function resolveFromForm(options) {
|
|
10457
|
-
var _a, _b, _c
|
|
10502
|
+
var _a, _b, _c;
|
|
10458
10503
|
const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
|
|
10459
10504
|
const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
|
|
10460
10505
|
fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
|
|
@@ -10463,6 +10508,7 @@ async function resolveFromForm(options) {
|
|
|
10463
10508
|
]);
|
|
10464
10509
|
const templateConfig = templateRow.config;
|
|
10465
10510
|
const templateFormSchema = templateRow.form_schema;
|
|
10511
|
+
const formSchema = formSchemaRow.schema;
|
|
10466
10512
|
if (templateFormSchema) {
|
|
10467
10513
|
if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
|
|
10468
10514
|
templateConfig.dynamicFields = templateFormSchema.dynamicFields;
|
|
@@ -10476,7 +10522,7 @@ async function resolveFromForm(options) {
|
|
|
10476
10522
|
if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
|
|
10477
10523
|
paintRepeatableSections(templateConfig, repeatableFromSchema);
|
|
10478
10524
|
}
|
|
10479
|
-
const schemaSections = (
|
|
10525
|
+
const schemaSections = getRenderableFormSections(formSchema);
|
|
10480
10526
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
10481
10527
|
if (repeatableFromSchema) {
|
|
10482
10528
|
for (const r of repeatableFromSchema) {
|
|
@@ -10487,12 +10533,12 @@ async function resolveFromForm(options) {
|
|
|
10487
10533
|
let inferredSections;
|
|
10488
10534
|
if (schemaSections == null ? void 0 : schemaSections.length) {
|
|
10489
10535
|
inferredSections = formDefSectionsToInferred(schemaSections, repeatableNodeMap);
|
|
10490
|
-
} else if ((
|
|
10536
|
+
} else if ((_a = templateConfig.dynamicFields) == null ? void 0 : _a.length) {
|
|
10491
10537
|
const groups = templateConfig.fieldGroups || [];
|
|
10492
10538
|
inferredSections = inferFormSchemaFromTemplate(
|
|
10493
10539
|
templateConfig.dynamicFields,
|
|
10494
10540
|
groups,
|
|
10495
|
-
((
|
|
10541
|
+
((_b = templateConfig.pages) == null ? void 0 : _b.length) ? { pages: templateConfig.pages } : void 0
|
|
10496
10542
|
);
|
|
10497
10543
|
} else {
|
|
10498
10544
|
inferredSections = [];
|
|
@@ -10577,9 +10623,10 @@ async function resolveFromForm(options) {
|
|
|
10577
10623
|
repeatableList.length > 0 ? repeatableList : repeatableFromSchema ?? [],
|
|
10578
10624
|
void 0,
|
|
10579
10625
|
Object.keys(repeatableNestedEntryCounts).length > 0 ? repeatableNestedEntryCounts : void 0,
|
|
10580
|
-
displayFormatMap.size > 0 ? displayFormatMap : void 0
|
|
10626
|
+
displayFormatMap.size > 0 ? displayFormatMap : void 0,
|
|
10627
|
+
buildRepeatablePagesInputForApply(formSchema, mergedSectionState)
|
|
10581
10628
|
);
|
|
10582
|
-
if ((
|
|
10629
|
+
if ((_c = resolvedConfig.themeConfig) == null ? void 0 : _c.variables) {
|
|
10583
10630
|
const baseOverrides = {};
|
|
10584
10631
|
for (const [key, def] of Object.entries(resolvedConfig.themeConfig.variables)) {
|
|
10585
10632
|
baseOverrides[key] = def.value;
|