@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.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const react = require("react");
|
|
|
8
8
|
const reactDom = require("react-dom");
|
|
9
9
|
const zustand = require("zustand");
|
|
10
10
|
const fabric = require("fabric");
|
|
11
|
+
const supabaseJs = require("@supabase/supabase-js");
|
|
11
12
|
const client = require("react-dom/client");
|
|
12
13
|
const jspdf = require("jspdf");
|
|
13
14
|
const svg2pdf_js = require("svg2pdf.js");
|
|
@@ -8783,6 +8784,50 @@ function applyThemeToConfig(config, themeOverrides) {
|
|
|
8783
8784
|
}
|
|
8784
8785
|
return cloned;
|
|
8785
8786
|
}
|
|
8787
|
+
const SUPABASE_URL = void 0;
|
|
8788
|
+
const SUPABASE_PUBLISHABLE_KEY = void 0;
|
|
8789
|
+
supabaseJs.createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, {
|
|
8790
|
+
auth: {
|
|
8791
|
+
storage: localStorage,
|
|
8792
|
+
persistSession: true,
|
|
8793
|
+
autoRefreshToken: true
|
|
8794
|
+
}
|
|
8795
|
+
});
|
|
8796
|
+
function repeatablePageToSection(page) {
|
|
8797
|
+
return {
|
|
8798
|
+
id: page.id,
|
|
8799
|
+
label: page.label,
|
|
8800
|
+
description: page.description,
|
|
8801
|
+
// Place pages after sections by default; explicit order preserved.
|
|
8802
|
+
order: typeof page.order === "number" ? page.order + 1e4 : 1e4,
|
|
8803
|
+
fields: page.fields,
|
|
8804
|
+
repeatable: true,
|
|
8805
|
+
minEntries: page.minEntries,
|
|
8806
|
+
maxEntries: page.maxEntries,
|
|
8807
|
+
templateKeyPrefix: page.templateKeyPrefix,
|
|
8808
|
+
children: page.children
|
|
8809
|
+
};
|
|
8810
|
+
}
|
|
8811
|
+
function getRenderableFormSections(schema) {
|
|
8812
|
+
if (!schema) return [];
|
|
8813
|
+
const base = schema.sections ?? [];
|
|
8814
|
+
const pages = schema.repeatablePages ?? [];
|
|
8815
|
+
if (!pages.length) return base;
|
|
8816
|
+
return [...base, ...pages.map(repeatablePageToSection)];
|
|
8817
|
+
}
|
|
8818
|
+
function buildRepeatablePagesInputForApply(schema, sectionState) {
|
|
8819
|
+
var _a;
|
|
8820
|
+
if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
|
|
8821
|
+
return schema.repeatablePages.map((p) => {
|
|
8822
|
+
const entries = sectionState == null ? void 0 : sectionState[p.id];
|
|
8823
|
+
const minEntries = p.minEntries != null ? Math.max(0, p.minEntries) : 1;
|
|
8824
|
+
let entryCount;
|
|
8825
|
+
if (Array.isArray(entries)) {
|
|
8826
|
+
entryCount = minEntries === 0 ? entries.length : Math.max(1, entries.length);
|
|
8827
|
+
}
|
|
8828
|
+
return { pageId: p.id, templateKeyPrefix: p.templateKeyPrefix, entryCount };
|
|
8829
|
+
});
|
|
8830
|
+
}
|
|
8786
8831
|
function mapFormDefFieldType(t) {
|
|
8787
8832
|
if (["text", "email", "tel", "textarea", "date", "url", "number", "toggle", "color", "image"].includes(t)) return t;
|
|
8788
8833
|
if (t === "currency") return "number";
|
|
@@ -10473,7 +10518,7 @@ async function resolveTemplateData(options) {
|
|
|
10473
10518
|
};
|
|
10474
10519
|
}
|
|
10475
10520
|
async function resolveFromForm(options) {
|
|
10476
|
-
var _a, _b, _c
|
|
10521
|
+
var _a, _b, _c;
|
|
10477
10522
|
const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
|
|
10478
10523
|
const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
|
|
10479
10524
|
fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
|
|
@@ -10482,6 +10527,7 @@ async function resolveFromForm(options) {
|
|
|
10482
10527
|
]);
|
|
10483
10528
|
const templateConfig = templateRow.config;
|
|
10484
10529
|
const templateFormSchema = templateRow.form_schema;
|
|
10530
|
+
const formSchema = formSchemaRow.schema;
|
|
10485
10531
|
if (templateFormSchema) {
|
|
10486
10532
|
if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
|
|
10487
10533
|
templateConfig.dynamicFields = templateFormSchema.dynamicFields;
|
|
@@ -10495,7 +10541,7 @@ async function resolveFromForm(options) {
|
|
|
10495
10541
|
if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
|
|
10496
10542
|
paintRepeatableSections(templateConfig, repeatableFromSchema);
|
|
10497
10543
|
}
|
|
10498
|
-
const schemaSections = (
|
|
10544
|
+
const schemaSections = getRenderableFormSections(formSchema);
|
|
10499
10545
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
10500
10546
|
if (repeatableFromSchema) {
|
|
10501
10547
|
for (const r of repeatableFromSchema) {
|
|
@@ -10506,12 +10552,12 @@ async function resolveFromForm(options) {
|
|
|
10506
10552
|
let inferredSections;
|
|
10507
10553
|
if (schemaSections == null ? void 0 : schemaSections.length) {
|
|
10508
10554
|
inferredSections = formDefSectionsToInferred(schemaSections, repeatableNodeMap);
|
|
10509
|
-
} else if ((
|
|
10555
|
+
} else if ((_a = templateConfig.dynamicFields) == null ? void 0 : _a.length) {
|
|
10510
10556
|
const groups = templateConfig.fieldGroups || [];
|
|
10511
10557
|
inferredSections = inferFormSchemaFromTemplate(
|
|
10512
10558
|
templateConfig.dynamicFields,
|
|
10513
10559
|
groups,
|
|
10514
|
-
((
|
|
10560
|
+
((_b = templateConfig.pages) == null ? void 0 : _b.length) ? { pages: templateConfig.pages } : void 0
|
|
10515
10561
|
);
|
|
10516
10562
|
} else {
|
|
10517
10563
|
inferredSections = [];
|
|
@@ -10596,9 +10642,10 @@ async function resolveFromForm(options) {
|
|
|
10596
10642
|
repeatableList.length > 0 ? repeatableList : repeatableFromSchema ?? [],
|
|
10597
10643
|
void 0,
|
|
10598
10644
|
Object.keys(repeatableNestedEntryCounts).length > 0 ? repeatableNestedEntryCounts : void 0,
|
|
10599
|
-
displayFormatMap.size > 0 ? displayFormatMap : void 0
|
|
10645
|
+
displayFormatMap.size > 0 ? displayFormatMap : void 0,
|
|
10646
|
+
buildRepeatablePagesInputForApply(formSchema, mergedSectionState)
|
|
10600
10647
|
);
|
|
10601
|
-
if ((
|
|
10648
|
+
if ((_c = resolvedConfig.themeConfig) == null ? void 0 : _c.variables) {
|
|
10602
10649
|
const baseOverrides = {};
|
|
10603
10650
|
for (const [key, def] of Object.entries(resolvedConfig.themeConfig.variables)) {
|
|
10604
10651
|
baseOverrides[key] = def.value;
|