@antelopejs/dms 0.25.6-next.1105.g9b73018 → 0.25.6
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/CHANGELOG.md +60 -0
- package/README.md +16 -16
- package/data/mockup-spec.schema.json +289 -5
- package/dist/implementations/dms-auth/account-emails.js +2 -2
- package/dist/implementations/dms-auth/account-emails.js.map +1 -1
- package/dist/implementations/dms-auth/index.js +1 -2
- package/dist/implementations/dms-auth/index.js.map +1 -1
- package/dist/implementations/dms-base/group-order.d.ts +18 -0
- package/dist/implementations/dms-base/group-order.js +66 -0
- package/dist/implementations/dms-base/group-order.js.map +1 -0
- package/dist/implementations/dms-base/search-route.js +8 -5
- package/dist/implementations/dms-base/search-route.js.map +1 -1
- package/dist/implementations/dms-builder/engine/cell-displays.js +4 -1
- package/dist/implementations/dms-builder/engine/cell-displays.js.map +1 -1
- package/dist/implementations/dms-builder/engine/mapped-displays.js +5 -1
- package/dist/implementations/dms-builder/engine/mapped-displays.js.map +1 -1
- package/dist/implementations/dms-builder/engine/resource-emit.js +4 -0
- package/dist/implementations/dms-builder/engine/resource-emit.js.map +1 -1
- package/dist/implementations/dms-builder/engine/theme-assets.js +5 -17
- package/dist/implementations/dms-builder/engine/theme-assets.js.map +1 -1
- package/dist/mcp/tools/mockup-apply-to-page.js +1 -1
- package/dist/mcp/tools/mockup-apply-to-page.js.map +1 -1
- package/dist/mcp/tools/mockup-patch-spec.js +1 -1
- package/dist/mcp/tools/mockup-patch-spec.js.map +1 -1
- package/dist/mcp/tools/mockup-write-spec.js +1 -1
- package/dist/mcp/tools/mockup-write-spec.js.map +1 -1
- package/dist/mockup/apply-notes.d.ts +1 -1
- package/dist/mockup/apply-notes.js +2 -1
- package/dist/mockup/apply-notes.js.map +1 -1
- package/dist/mockup/apply-plan.js +3 -0
- package/dist/mockup/apply-plan.js.map +1 -1
- package/dist/mockup/capture-routes.d.ts +18 -0
- package/dist/mockup/capture-routes.js +101 -0
- package/dist/mockup/capture-routes.js.map +1 -0
- package/dist/mockup/capture.d.ts +10 -0
- package/dist/mockup/capture.js +64 -0
- package/dist/mockup/capture.js.map +1 -0
- package/dist/mockup/compile.js +16 -8
- package/dist/mockup/compile.js.map +1 -1
- package/dist/mockup/controller-blocks.js +62 -10
- package/dist/mockup/controller-blocks.js.map +1 -1
- package/dist/mockup/display-values.js +1 -1
- package/dist/mockup/display-values.js.map +1 -1
- package/dist/mockup/files.d.ts +2 -1
- package/dist/mockup/files.js +3 -2
- package/dist/mockup/files.js.map +1 -1
- package/dist/mockup/fixtures.d.ts +3 -1
- package/dist/mockup/fixtures.js +25 -2
- package/dist/mockup/fixtures.js.map +1 -1
- package/dist/mockup/form-fields.js +10 -1
- package/dist/mockup/form-fields.js.map +1 -1
- package/dist/mockup/header-action.d.ts +47 -0
- package/dist/mockup/header-action.js +46 -0
- package/dist/mockup/header-action.js.map +1 -0
- package/dist/mockup/history-routes.js +8 -1
- package/dist/mockup/history-routes.js.map +1 -1
- package/dist/mockup/json-schema-header.d.ts +2 -0
- package/dist/mockup/json-schema-header.js +69 -0
- package/dist/mockup/json-schema-header.js.map +1 -0
- package/dist/mockup/json-schema-layout.d.ts +2 -0
- package/dist/mockup/json-schema-layout.js +61 -0
- package/dist/mockup/json-schema-layout.js.map +1 -0
- package/dist/mockup/json-schema.js +5 -16
- package/dist/mockup/json-schema.js.map +1 -1
- package/dist/mockup/model.d.ts +204 -18
- package/dist/mockup/model.js +46 -12
- package/dist/mockup/model.js.map +1 -1
- package/dist/mockup/page-links.d.ts +2 -1
- package/dist/mockup/page-links.js +14 -3
- package/dist/mockup/page-links.js.map +1 -1
- package/dist/mockup/refusals.d.ts +1 -0
- package/dist/mockup/refusals.js +1 -0
- package/dist/mockup/refusals.js.map +1 -1
- package/dist/mockup/routes.js +11 -1
- package/dist/mockup/routes.js.map +1 -1
- package/dist/mockup/sample-rows.js +4 -0
- package/dist/mockup/sample-rows.js.map +1 -1
- package/dist/mockup/store.d.ts +1 -0
- package/dist/mockup/store.js +9 -19
- package/dist/mockup/store.js.map +1 -1
- package/dist/mockup/summary-fields.d.ts +20 -0
- package/dist/mockup/summary-fields.js +22 -0
- package/dist/mockup/summary-fields.js.map +1 -0
- package/dist/mockup/table-columns.js +9 -3
- package/dist/mockup/table-columns.js.map +1 -1
- package/dist/mockup/table-options.d.ts +4 -1
- package/dist/mockup/table-options.js +40 -2
- package/dist/mockup/table-options.js.map +1 -1
- package/dist/mockup/table-param-filters.d.ts +52 -0
- package/dist/mockup/table-param-filters.js +83 -0
- package/dist/mockup/table-param-filters.js.map +1 -0
- package/dist/mockup/table-row-actions.d.ts +2 -0
- package/dist/mockup/table-row-actions.js +85 -0
- package/dist/mockup/table-row-actions.js.map +1 -0
- package/dist/mockup/unknown-keys.d.ts +3 -0
- package/dist/mockup/unknown-keys.js +45 -0
- package/dist/mockup/unknown-keys.js.map +1 -0
- package/dist/mockup/validate.d.ts +7 -1
- package/dist/mockup/validate.js +76 -3
- package/dist/mockup/validate.js.map +1 -1
- package/dist/pages/account.d.ts +1 -0
- package/dist/pages/account.js +1 -0
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/settings/overview/account-summary.d.ts +2 -0
- package/dist/pages/settings/overview/account-summary.js +17 -8
- package/dist/pages/settings/overview/account-summary.js.map +1 -1
- package/dist/pages/settings/settings-index.js +2 -1
- package/dist/pages/settings/settings-index.js.map +1 -1
- package/dist/realtime/sse.js +2 -4
- package/dist/realtime/sse.js.map +1 -1
- package/dist/store/internal/frontend/dev-reload.js +7 -1
- package/dist/store/internal/frontend/dev-reload.js.map +1 -1
- package/dist/utils/account-notifications.js +1 -0
- package/dist/utils/account-notifications.js.map +1 -1
- package/dist/utils/email-change-mail.js +2 -2
- package/dist/utils/email-change-mail.js.map +1 -1
- package/dist/utils/email-plain-text.d.ts +1 -0
- package/dist/utils/email-plain-text.js +95 -0
- package/dist/utils/email-plain-text.js.map +1 -0
- package/dist/utils/export-jobs.js +2 -2
- package/dist/utils/export-jobs.js.map +1 -1
- package/dist/utils/html-email.d.ts +8 -0
- package/dist/utils/html-email.js +9 -0
- package/dist/utils/html-email.js.map +1 -0
- package/dist/utils/image-signatures.d.ts +3 -0
- package/dist/utils/image-signatures.js +22 -0
- package/dist/utils/image-signatures.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/sse-keepalive/index.d.ts +3 -0
- package/dist/utils/sse-keepalive/index.js +8 -0
- package/dist/utils/sse-keepalive/index.js.map +1 -0
- package/dist/validation/allowed-keys.d.ts +2 -0
- package/dist/validation/allowed-keys.js +16 -0
- package/dist/validation/allowed-keys.js.map +1 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -0
- package/dist/validation/index.js.map +1 -1
- package/frontend-vue/eslint-globals.generated.mjs +2 -2
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/2fa.vue +3 -0
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/backup.vue +3 -0
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/forgot-validation.vue +3 -0
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/forgot.vue +3 -0
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/login.vue +4 -1
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/recover.vue +3 -0
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/signup.vue +17 -1
- package/frontend-vue/layers/dms-auth/app/custom-pages/auth/validate.vue +3 -0
- package/frontend-vue/layers/dms-auth/i18n/locales/auth-fr-FR.json +10 -10
- package/frontend-vue/layers/dms-core/app/build/composables/api-error.ts +8 -0
- package/frontend-vue/layers/dms-core/app/build/composables/field-errors.ts +485 -0
- package/frontend-vue/layers/dms-core/app/build/composables/useHydrated.ts +27 -0
- package/frontend-vue/layers/dms-core/app/composables/data-types/useDataType.ts +3 -2
- package/frontend-vue/layers/dms-core/app/composables/translation/useUniqueLocales.ts +23 -5
- package/frontend-vue/layers/dms-core/app/composables/useApiErrorPresenter.ts +1 -0
- package/frontend-vue/layers/dms-core/app/composables/useFieldErrors.ts +12 -443
- package/frontend-vue/layers/dms-core/app/entries/composables/useHydrated.ts +1 -0
- package/frontend-vue/layers/dms-core/i18n/locales/core-en-GB.json +8 -0
- package/frontend-vue/layers/dms-core/i18n/locales/core-fr-FR.json +8 -0
- package/frontend-vue/layers/dms-core/shared/types/app-config.ts +2 -0
- package/frontend-vue/layers/dms-layout/app/app.config.ts +1 -0
- package/frontend-vue/layers/dms-layout/app/build/components/layout/DashboardHeader.vue +7 -4
- package/frontend-vue/layers/dms-layout/app/build/components/layout/EmptyLayoutBrand.vue +49 -0
- package/frontend-vue/layers/dms-layout/app/build/components/layout/LayoutFooter.vue +2 -0
- package/frontend-vue/layers/dms-layout/app/build/components/layout/PreviewPageHeader.vue +19 -3
- package/frontend-vue/layers/dms-layout/app/build/components/layout/mockupMenu.ts +3 -8
- package/frontend-vue/layers/dms-layout/app/build/components/notification/NotificationPopover.vue +8 -2
- package/frontend-vue/layers/dms-layout/app/build/components/pages/settings/notification/NotificationInboxItem.vue +6 -9
- package/frontend-vue/layers/dms-layout/app/build/components/pages/settings/notification/NotificationMatrixCategory.vue +6 -2
- package/frontend-vue/layers/dms-layout/app/build/components/pages/settings/notification/NotificationMatrixSubject.vue +27 -22
- package/frontend-vue/layers/dms-layout/app/build/components/pages/settings/notification/NotificationPreferencesForm.vue +8 -10
- package/frontend-vue/layers/dms-layout/app/build/components/pages/settings/notification/notificationDisplay.ts +39 -3
- package/frontend-vue/layers/dms-layout/app/build/components/pages/settings/shell/SettingsShell.vue +38 -5
- package/frontend-vue/layers/dms-layout/app/build/composables/settings/profile/useProfilePreferences.ts +1 -3
- package/frontend-vue/layers/dms-layout/app/build/utils/dev-reload-stream.ts +23 -4
- package/frontend-vue/layers/dms-layout/app/custom-layouts/EmptyLayout.vue +39 -31
- package/frontend-vue/layers/dms-layout/app/custom-layouts/PreviewLayout.vue +60 -4
- package/frontend-vue/layers/dms-layout/app/entries/components/pages/settings/shell/SettingsShell.ts +2 -0
- package/frontend-vue/layers/dms-layout/app/error.vue +1 -1
- package/frontend-vue/layers/dms-layout/app/middleware/module-routing.global.ts +7 -1
- package/frontend-vue/layers/dms-layout/app/plugins/dms-menu-sync.client.ts +14 -1
- package/frontend-vue/layers/dms-layout/app/utils/breadcrumb.ts +13 -0
- package/frontend-vue/layers/dms-layout/i18n/locales/layout-en-GB.json +1 -1
- package/frontend-vue/layers/dms-layout/i18n/locales/layout-fr-FR.json +5 -5
- package/frontend-vue/layers/dms-onboarding/app/build/components/onboarding/steps/StepPlatform.vue +3 -0
- package/frontend-vue/layers/dms-onboarding/app/components/onboarding/steps/StepRegister.vue +3 -1
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/BlockPreviewSketch.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupHeaderActions.vue +1 -4
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupInspector.vue +2 -1
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupIssues.vue +22 -1
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupOverview.vue +125 -178
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupOverviewArrows.vue +110 -0
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupOverviewFrameImage.vue +75 -0
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupOverviewSlot.vue +113 -4
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupOverviewZoom.vue +67 -0
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupPinLayer.vue +10 -4
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupWorkbench.vue +8 -1
- package/frontend-vue/layers/dms-ui/app/build/components/table-view/ExpandedRowDetail.vue +26 -6
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/previewCapture.ts +247 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/previewCaptureAssets.ts +181 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/previewNavigation.ts +8 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/previewRaster.ts +45 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useBlockPreviewEmbed.ts +46 -6
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupOverview.ts +109 -35
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupPageFrame.ts +4 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupRoutePage.ts +4 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupViewerPages.ts +3 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useOverviewCaptures.ts +136 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/usePreviewFrame.ts +68 -8
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/usePreviewLinks.ts +17 -7
- package/frontend-vue/layers/dms-ui/app/build/composables/confirm/fetchedConfirmDialog.ts +6 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/data-types/defaultDisplayComponents.ts +4 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/data-types/defaultPrimitiveTypes.ts +38 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/data-types/registerFieldTypes.ts +69 -3
- package/frontend-vue/layers/dms-ui/app/build/composables/data-types/useColumnValueRenderer.ts +20 -7
- package/frontend-vue/layers/dms-ui/app/build/composables/form/keyValueRows.ts +36 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/form/useInstantForm.ts +4 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewGrouping.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewListing.ts +21 -5
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableViewSorting.ts +8 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useGroupedRows.ts +32 -4
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useTableFooter.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useTableRows.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/displayOptions.ts +14 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/groupedRows.ts +68 -6
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/tableQuery.ts +5 -0
- package/frontend-vue/layers/dms-ui/app/build/mockups/MockupCard.vue +73 -48
- package/frontend-vue/layers/dms-ui/app/build/mockups/MockupCards.vue +18 -11
- package/frontend-vue/layers/dms-ui/app/build/mockups/MockupThumbnail.vue +34 -124
- package/frontend-vue/layers/dms-ui/app/build/mockups/manage.ts +7 -3
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewCapture.ts +96 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewChannel.ts +10 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewMessages.ts +29 -118
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewRects.ts +61 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/dotGrid.ts +37 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/legalIdentifier.ts +279 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/mockup.ts +34 -5
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupCaptures.ts +130 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupFrame.ts +6 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupLinks.ts +35 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupOverview.ts +44 -17
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupSpec.ts +26 -14
- package/frontend-vue/layers/dms-ui/app/build/utils/previewHeader.ts +154 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/previewPageLayout.ts +149 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/previewPageQuery.ts +42 -0
- package/frontend-vue/layers/dms-ui/app/components/block-preview/BlockPreview.vue +56 -6
- package/frontend-vue/layers/dms-ui/app/components/confirm/ConfirmModal.vue +7 -7
- package/frontend-vue/layers/dms-ui/app/components/flow-canvas/FlowCanvas.vue +4 -7
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputIdentifier.vue +90 -0
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputPhone.vue +5 -0
- package/frontend-vue/layers/dms-ui/app/components/form/components/KeyValue.vue +2 -20
- package/frontend-vue/layers/dms-ui/app/components/key-value-list/KeyValueList.vue +51 -15
- package/frontend-vue/layers/dms-ui/app/composables/form/useForm.ts +3 -8
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/config.ts +10 -0
- package/frontend-vue/layers/dms-ui/app/entries/composables/block-preview/previewCapture.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/entries/composables/block-preview/previewCaptureAssets.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/entries/composables/block-preview/usePreviewFrame.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/entries/composables/table-view/utils/displayOptions.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/entries/mockups/manage.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/entries/utils/blockPreview.ts +3 -0
- package/frontend-vue/layers/dms-ui/app/entries/utils/legalIdentifier.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/entries/utils/mockupCaptures.ts +1 -0
- package/frontend-vue/layers/dms-ui/app/types/table/query.ts +5 -0
- package/frontend-vue/layers/dms-ui/i18n/locales/ui-en-GB.json +2 -0
- package/frontend-vue/layers/dms-ui/i18n/locales/ui-fr-FR.json +12 -10
- package/frontend-vue/scripts/check-invariants.mjs +101 -0
- package/package.json +8 -8
- package/skills/dms/SKILL.md +4 -2
- package/skills/dms-module/SKILL.md +3 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/** A country whose company registration number is read. */
|
|
2
|
+
export type CompanyNumberCountry = "BE" | "FR";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a person types, without its spaces, dots, dashes and
|
|
6
|
+
* slashes, in upper case.
|
|
7
|
+
*/
|
|
8
|
+
export function compactIdentifier(value: string): string {
|
|
9
|
+
return value.replace(/[\s.\-/]/g, "").toUpperCase();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The remainder of a digit string of any length divided by 97. */
|
|
13
|
+
function mod97(digits: string): number {
|
|
14
|
+
let remainder = 0;
|
|
15
|
+
for (const digit of digits) {
|
|
16
|
+
remainder = (remainder * 10 + Number(digit)) % 97;
|
|
17
|
+
}
|
|
18
|
+
return remainder;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Whether a digit string passes the Luhn check (ISO/IEC 7812). */
|
|
22
|
+
function passesLuhn(digits: string): boolean {
|
|
23
|
+
let sum = 0;
|
|
24
|
+
for (let index = 0; index < digits.length; index++) {
|
|
25
|
+
const digit = Number(digits[digits.length - 1 - index]);
|
|
26
|
+
const weighted = index % 2 === 1 ? digit * 2 : digit;
|
|
27
|
+
sum += weighted > 9 ? weighted - 9 : weighted;
|
|
28
|
+
}
|
|
29
|
+
return sum % 10 === 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const IBAN = /^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An IBAN without spaces (`BE68539007547034`), checked against its
|
|
36
|
+
* two check digits (ISO 13616, modulo 97); `undefined` when it is none.
|
|
37
|
+
*/
|
|
38
|
+
export function readIban(value: string): string | undefined {
|
|
39
|
+
const iban = compactIdentifier(value);
|
|
40
|
+
if (!IBAN.test(iban)) return undefined;
|
|
41
|
+
const numeric = `${iban.slice(4)}${iban.slice(0, 4)}`.replace(
|
|
42
|
+
/[A-Z]/g,
|
|
43
|
+
(letter) => String(letter.charCodeAt(0) - 55),
|
|
44
|
+
);
|
|
45
|
+
return mod97(numeric) === 1 ? iban : undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** An IBAN as printed, in groups of four: `BE68 5390 0754 7034`. */
|
|
49
|
+
export function formatIban(iban: string): string {
|
|
50
|
+
return iban.replace(/(.{4})(?=.)/g, "$1 ");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const BIC = /^[A-Z0-9]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$/;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A BIC of 8 or 11 characters (ISO 9362): party prefix, country,
|
|
57
|
+
* location and an optional branch; `undefined` when it is none.
|
|
58
|
+
*/
|
|
59
|
+
export function readBic(value: string): string | undefined {
|
|
60
|
+
const bic = compactIdentifier(value);
|
|
61
|
+
return BIC.test(bic) ? bic : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The ten digits of a Belgian enterprise number, or `undefined`. */
|
|
65
|
+
function readBelgianEnterpriseNumber(digits: string): string | undefined {
|
|
66
|
+
const number = digits.length === 9 ? `0${digits}` : digits;
|
|
67
|
+
if (!/^[01]\d{9}$/.test(number)) return undefined;
|
|
68
|
+
const check = 97 - mod97(number.slice(0, 8));
|
|
69
|
+
return check === Number(number.slice(8)) ? number : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The nine digits of a French SIREN, or `undefined`. */
|
|
73
|
+
function readSiren(digits: string): string | undefined {
|
|
74
|
+
return /^\d{9}$/.test(digits) && passesLuhn(digits) ? digits : undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const COMPANY_NUMBER_READERS = new Map<
|
|
78
|
+
string,
|
|
79
|
+
(digits: string) => string | undefined
|
|
80
|
+
>([
|
|
81
|
+
["BE", readBelgianEnterpriseNumber],
|
|
82
|
+
["FR", readSiren],
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
/** Whether `country` is one whose company number is read. */
|
|
86
|
+
export function isCompanyNumberCountry(
|
|
87
|
+
country: unknown,
|
|
88
|
+
): country is CompanyNumberCountry {
|
|
89
|
+
return typeof country === "string" && COMPANY_NUMBER_READERS.has(country);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A company registration number of `country` as its register
|
|
94
|
+
* writes it, digits only: a Belgian enterprise number of ten digits (the
|
|
95
|
+
* nine of before 2005 get their leading zero), a French SIREN of nine.
|
|
96
|
+
* Typed with its country's code in front (`BE 0123.456.749`), it reads the
|
|
97
|
+
* same. `undefined` when it is none.
|
|
98
|
+
*/
|
|
99
|
+
export function readCompanyNumber(
|
|
100
|
+
value: string,
|
|
101
|
+
country: CompanyNumberCountry,
|
|
102
|
+
): string | undefined {
|
|
103
|
+
const compact = compactIdentifier(value);
|
|
104
|
+
const digits = compact.startsWith(country)
|
|
105
|
+
? compact.slice(country.length)
|
|
106
|
+
: compact;
|
|
107
|
+
return COMPANY_NUMBER_READERS.get(country)?.(digits);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A company registration number as its country prints it:
|
|
112
|
+
* `0123.456.749` in Belgium, `123 456 782` in France.
|
|
113
|
+
*/
|
|
114
|
+
export function formatCompanyNumber(
|
|
115
|
+
number: string,
|
|
116
|
+
country: CompanyNumberCountry,
|
|
117
|
+
): string {
|
|
118
|
+
if (country === "BE") {
|
|
119
|
+
return `${number.slice(0, 4)}.${number.slice(4, 7)}.${number.slice(7)}`;
|
|
120
|
+
}
|
|
121
|
+
return number.replace(/(\d{3})(?=\d)/g, "$1 ");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The format of each country's VAT number after its country code, as the
|
|
126
|
+
* EU's VIES service lists it, plus Northern Ireland (`XI`) and Great Britain.
|
|
127
|
+
*/
|
|
128
|
+
const VAT_NUMBER_FORMATS = new Map<string, RegExp>([
|
|
129
|
+
["AT", /^U\d{8}$/],
|
|
130
|
+
["BE", /^[01]\d{9}$/],
|
|
131
|
+
["BG", /^\d{9,10}$/],
|
|
132
|
+
["CY", /^\d{8}[A-Z]$/],
|
|
133
|
+
["CZ", /^\d{8,10}$/],
|
|
134
|
+
["DE", /^\d{9}$/],
|
|
135
|
+
["DK", /^\d{8}$/],
|
|
136
|
+
["EE", /^\d{9}$/],
|
|
137
|
+
["EL", /^\d{9}$/],
|
|
138
|
+
["ES", /^[A-Z0-9]\d{7}[A-Z0-9]$/],
|
|
139
|
+
["FI", /^\d{8}$/],
|
|
140
|
+
["FR", /^[A-HJ-NP-Z0-9]{2}\d{9}$/],
|
|
141
|
+
["GB", /^(?:\d{9}|\d{12}|GD\d{3}|HA\d{3})$/],
|
|
142
|
+
["HR", /^\d{11}$/],
|
|
143
|
+
["HU", /^\d{8}$/],
|
|
144
|
+
["IE", /^(?:\d{7}[A-W][A-IW]?|\d[A-Z+*]\d{5}[A-W])$/],
|
|
145
|
+
["IT", /^\d{11}$/],
|
|
146
|
+
["LT", /^(?:\d{9}|\d{12})$/],
|
|
147
|
+
["LU", /^\d{8}$/],
|
|
148
|
+
["LV", /^\d{11}$/],
|
|
149
|
+
["MT", /^\d{8}$/],
|
|
150
|
+
["NL", /^\d{9}B\d{2}$/],
|
|
151
|
+
["PL", /^\d{10}$/],
|
|
152
|
+
["PT", /^\d{9}$/],
|
|
153
|
+
["RO", /^[1-9]\d{1,9}$/],
|
|
154
|
+
["SE", /^\d{10}01$/],
|
|
155
|
+
["SI", /^\d{8}$/],
|
|
156
|
+
["SK", /^\d{10}$/],
|
|
157
|
+
["XI", /^(?:\d{9}|\d{12}|GD\d{3}|HA\d{3})$/],
|
|
158
|
+
]);
|
|
159
|
+
|
|
160
|
+
/** German VAT check digit: ISO 7064 MOD 11,10 over the first eight digits. */
|
|
161
|
+
function passesGermanCheck(number: string): boolean {
|
|
162
|
+
let product = 10;
|
|
163
|
+
for (const digit of number.slice(0, 8)) {
|
|
164
|
+
let sum = (Number(digit) + product) % 10;
|
|
165
|
+
if (sum === 0) sum = 10;
|
|
166
|
+
product = (2 * sum) % 11;
|
|
167
|
+
}
|
|
168
|
+
const check = (11 - product) % 10;
|
|
169
|
+
return check === Number(number[8]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** French VAT key: `(12 + 3 × (SIREN mod 97)) mod 97`, when it is numeric. */
|
|
173
|
+
function passesFrenchCheck(number: string): boolean {
|
|
174
|
+
const key = number.slice(0, 2);
|
|
175
|
+
if (!/^\d{2}$/.test(key)) return true;
|
|
176
|
+
const siren = number.slice(2);
|
|
177
|
+
return Number(key) === (12 + 3 * mod97(siren)) % 97;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Luxembourg VAT: the first six digits modulo 89 are the last two. */
|
|
181
|
+
function passesLuxembourgCheck(number: string): boolean {
|
|
182
|
+
return Number(number.slice(0, 6)) % 89 === Number(number.slice(6));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The check digits of the countries whose public rule is stable; the format only elsewhere. */
|
|
186
|
+
const VAT_CHECKS = new Map<string, (number: string) => boolean>([
|
|
187
|
+
["BE", (number) => readBelgianEnterpriseNumber(number) !== undefined],
|
|
188
|
+
["DE", passesGermanCheck],
|
|
189
|
+
["FR", passesFrenchCheck],
|
|
190
|
+
["IT", passesLuhn],
|
|
191
|
+
["LU", passesLuxembourgCheck],
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
/** The code a person may type for a VAT country, read as VIES writes it. */
|
|
195
|
+
const VAT_PREFIX_ALIASES = new Map([["GR", "EL"]]);
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* A VAT number as VIES writes it (`BE0123456749`): its country's
|
|
199
|
+
* code, then its number without spaces. The number must have its country's
|
|
200
|
+
* format; Belgium, Germany, France, Italy and Luxembourg also check its check
|
|
201
|
+
* digits. A number typed without its country's code reads in
|
|
202
|
+
* `defaultCountry`, and a Belgian one of nine digits gets its leading zero.
|
|
203
|
+
* `undefined` when it is none.
|
|
204
|
+
*/
|
|
205
|
+
export function readVatNumber(
|
|
206
|
+
value: string,
|
|
207
|
+
defaultCountry?: string,
|
|
208
|
+
): string | undefined {
|
|
209
|
+
const compact = compactIdentifier(value);
|
|
210
|
+
const typedPrefix = compact.slice(0, 2);
|
|
211
|
+
const isPrefixed = /^[A-Z]{2}$/.test(typedPrefix);
|
|
212
|
+
const prefix = isPrefixed ? typedPrefix : defaultCountry?.toUpperCase();
|
|
213
|
+
if (!prefix) return undefined;
|
|
214
|
+
const country = VAT_PREFIX_ALIASES.get(prefix) ?? prefix;
|
|
215
|
+
const format = VAT_NUMBER_FORMATS.get(country);
|
|
216
|
+
if (!format) return undefined;
|
|
217
|
+
const typed = isPrefixed ? compact.slice(2) : compact;
|
|
218
|
+
const number = country === "BE" && typed.length === 9 ? `0${typed}` : typed;
|
|
219
|
+
if (!format.test(number)) return undefined;
|
|
220
|
+
const check = VAT_CHECKS.get(country);
|
|
221
|
+
if (check && !check(number)) return undefined;
|
|
222
|
+
return `${country}${number}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The identifier a field holds; the input's `identifier` option. */
|
|
226
|
+
export type IdentifierKind = "iban" | "bic" | "vat_number" | "company_number";
|
|
227
|
+
|
|
228
|
+
/** The options of the identifier input a reading depends on. */
|
|
229
|
+
export interface IdentifierRule {
|
|
230
|
+
identifier: IdentifierKind;
|
|
231
|
+
/** `vat_number`: the country a number without its code is read in. */
|
|
232
|
+
defaultCountry?: string;
|
|
233
|
+
/** `company_number`: the country whose register the number belongs to. */
|
|
234
|
+
country?: string;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const IDENTIFIER_READERS: Record<
|
|
238
|
+
IdentifierKind,
|
|
239
|
+
(value: string, rule: IdentifierRule) => string | undefined
|
|
240
|
+
> = {
|
|
241
|
+
iban: readIban,
|
|
242
|
+
bic: readBic,
|
|
243
|
+
vat_number: (value, rule) => readVatNumber(value, rule.defaultCountry),
|
|
244
|
+
company_number: (value, rule) =>
|
|
245
|
+
isCompanyNumberCountry(rule.country)
|
|
246
|
+
? readCompanyNumber(value, rule.country)
|
|
247
|
+
: undefined,
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The stored form of what was typed into an identifier input, or
|
|
252
|
+
* `undefined` when it is not an identifier of the field's kind.
|
|
253
|
+
*/
|
|
254
|
+
export function readIdentifier(
|
|
255
|
+
value: string,
|
|
256
|
+
rule: IdentifierRule,
|
|
257
|
+
): string | undefined {
|
|
258
|
+
return IDENTIFIER_READERS[rule.identifier](value, rule);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* A stored identifier as it is printed: an IBAN in groups of four, a
|
|
263
|
+
* company number as its country writes it, the others as stored.
|
|
264
|
+
*/
|
|
265
|
+
export function formatIdentifier(value: string, rule: IdentifierRule): string {
|
|
266
|
+
if (rule.identifier === "iban") return formatIban(value);
|
|
267
|
+
if (
|
|
268
|
+
rule.identifier === "company_number" &&
|
|
269
|
+
isCompanyNumberCountry(rule.country)
|
|
270
|
+
) {
|
|
271
|
+
return formatCompanyNumber(value, rule.country);
|
|
272
|
+
}
|
|
273
|
+
return value;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The message key a refused identifier of `kind` shows. */
|
|
277
|
+
export function identifierErrorKey(kind: IdentifierKind): string {
|
|
278
|
+
return `dms.field_errors.invalid_${kind}`;
|
|
279
|
+
}
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
isString,
|
|
5
5
|
} from "../../../../dms-core/app/utils/type-check";
|
|
6
6
|
import { isPreviewTree, type PreviewNode } from "./blockPreview";
|
|
7
|
+
import { isPreviewHeader, type PreviewHeaderAction } from "./previewHeader";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
} from "./
|
|
9
|
+
isPreviewPageLayout,
|
|
10
|
+
type PreviewPageLayout,
|
|
11
|
+
} from "./previewPageLayout";
|
|
11
12
|
|
|
12
13
|
/** A problem in `spec.json`, at a JSON pointer into it (`""` is the whole file). */
|
|
13
14
|
export interface MockupIssue {
|
|
@@ -60,6 +61,8 @@ export interface MockupPageState {
|
|
|
60
61
|
icon?: string;
|
|
61
62
|
description?: string;
|
|
62
63
|
headerActions?: PreviewHeaderAction[];
|
|
64
|
+
/** The layout the page is drawn in; the dashboard frame when absent. */
|
|
65
|
+
layout?: PreviewPageLayout;
|
|
63
66
|
options: MockupPageOptions;
|
|
64
67
|
/** What `DmsBlockPreview` draws: fixtures resolved, sketch nodes passed through. */
|
|
65
68
|
tree: PreviewNode[];
|
|
@@ -111,6 +114,8 @@ export interface MockupState {
|
|
|
111
114
|
modules?: MockupModule[];
|
|
112
115
|
pages: MockupPageState[];
|
|
113
116
|
issues: MockupIssue[];
|
|
117
|
+
/** What the spec likely does not show as meant; absent from a backend that reports none. */
|
|
118
|
+
warnings?: MockupIssue[];
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
export type MockupAnnotationStatus = "open" | "resolved";
|
|
@@ -208,6 +213,8 @@ interface MockupSummaryBase {
|
|
|
208
213
|
source?: MockupSource;
|
|
209
214
|
/** When `spec.json` last changed, ISO 8601. */
|
|
210
215
|
updatedAt: string;
|
|
216
|
+
/** When the stored image of the first page was last written, ISO 8601; absent when the mockup has none. */
|
|
217
|
+
capturedAt?: string;
|
|
211
218
|
}
|
|
212
219
|
|
|
213
220
|
/** One row of `GET /api/mockup`: a draft, or a mockup built into real pages. */
|
|
@@ -243,6 +250,9 @@ export const MOCKUP_WIDTHS: Record<MockupWidth, number> = {
|
|
|
243
250
|
|
|
244
251
|
export const MOCKUP_LIST_ENDPOINT = "/api/mockup";
|
|
245
252
|
|
|
253
|
+
/** The path under a mockup's endpoint of the stored image of its first page. */
|
|
254
|
+
export const MOCKUP_CAPTURE_SUFFIX = "/capture";
|
|
255
|
+
|
|
246
256
|
/** Event of the state stream carrying a {@link MockupState}. */
|
|
247
257
|
export const MOCKUP_STATE_EVENT = "state";
|
|
248
258
|
|
|
@@ -254,6 +264,21 @@ export function mockupEndpoint(name: string, suffix = ""): string {
|
|
|
254
264
|
return `${MOCKUP_LIST_ENDPOINT}/${encodeURIComponent(name)}${suffix}`;
|
|
255
265
|
}
|
|
256
266
|
|
|
267
|
+
/**
|
|
268
|
+
* The URL of the stored image of a mockup's first page. `capturedAt` makes
|
|
269
|
+
* it a new URL each time the image is written, so a browser that kept the
|
|
270
|
+
* old one asks again. `baseURL` is the API's own, which the session cookie
|
|
271
|
+
* authenticates an image request on.
|
|
272
|
+
*/
|
|
273
|
+
export function mockupCaptureUrl(
|
|
274
|
+
baseURL: string | undefined,
|
|
275
|
+
name: string,
|
|
276
|
+
capturedAt: string,
|
|
277
|
+
): string {
|
|
278
|
+
const origin = baseURL?.replace(/\/+$/, "") ?? "";
|
|
279
|
+
return `${origin}${mockupEndpoint(name, MOCKUP_CAPTURE_SUFFIX)}?v=${encodeURIComponent(capturedAt)}`;
|
|
280
|
+
}
|
|
281
|
+
|
|
257
282
|
export function isMockupWidth(value: string | undefined): value is MockupWidth {
|
|
258
283
|
return value !== undefined && Object.hasOwn(MOCKUP_WIDTHS, value);
|
|
259
284
|
}
|
|
@@ -333,6 +358,7 @@ function isPageState(
|
|
|
333
358
|
description: value.description,
|
|
334
359
|
actions: value.headerActions,
|
|
335
360
|
}) &&
|
|
361
|
+
(value.layout === undefined || isPreviewPageLayout(value.layout)) &&
|
|
336
362
|
isRecord(value.options) &&
|
|
337
363
|
Array.isArray(value.tree) &&
|
|
338
364
|
isPreviewTree(value.tree) &&
|
|
@@ -396,7 +422,9 @@ function isMockupState(
|
|
|
396
422
|
Array.isArray(value.pages) &&
|
|
397
423
|
value.pages.every(isPageState) &&
|
|
398
424
|
Array.isArray(value.issues) &&
|
|
399
|
-
value.issues.every(isIssue)
|
|
425
|
+
value.issues.every(isIssue) &&
|
|
426
|
+
(value.warnings === undefined ||
|
|
427
|
+
(Array.isArray(value.warnings) && value.warnings.every(isIssue)))
|
|
400
428
|
);
|
|
401
429
|
}
|
|
402
430
|
|
|
@@ -508,7 +536,8 @@ function isSummaryBase(
|
|
|
508
536
|
isNumber(value.pages) &&
|
|
509
537
|
isNumber(value.openComments) &&
|
|
510
538
|
(value.source === undefined || isSource(value.source)) &&
|
|
511
|
-
isString(value.updatedAt)
|
|
539
|
+
isString(value.updatedAt) &&
|
|
540
|
+
isOptionalString(value.capturedAt)
|
|
512
541
|
);
|
|
513
542
|
}
|
|
514
543
|
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { shallowRef, type Ref, type ShallowRef } from "vue";
|
|
2
|
+
import type {
|
|
3
|
+
PreviewBlockRect,
|
|
4
|
+
PreviewNavigation,
|
|
5
|
+
} from "./blockPreviewMessages";
|
|
6
|
+
import type { MockupPageState } from "./mockup";
|
|
7
|
+
import { mockupPageRender } from "./mockupFrame";
|
|
8
|
+
import { mockupDataTree } from "./mockupRealData";
|
|
9
|
+
|
|
10
|
+
/** The image of a page of a mockup, drawn once by the page's live preview. */
|
|
11
|
+
export interface PageCapture {
|
|
12
|
+
/** What drew the page, as {@link captureKey} names it: a page whose key is another is out of date. */
|
|
13
|
+
key: string;
|
|
14
|
+
/** An object URL of the image, WebP where the browser encodes it. */
|
|
15
|
+
url: string;
|
|
16
|
+
/** The height of the page the image shows, as its preview reported it. */
|
|
17
|
+
height?: number;
|
|
18
|
+
/** Where each block of the page sat in the image, for the pins of a frame no live preview reported. */
|
|
19
|
+
blocks?: PreviewBlockRect[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** What the live preview of a page reported of the drawing it was captured from. */
|
|
23
|
+
export interface CapturedLayout {
|
|
24
|
+
height?: number;
|
|
25
|
+
blocks?: PreviewBlockRect[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The captures of a mockup by page id. */
|
|
29
|
+
export type PageCaptures = ReadonlyMap<string, PageCapture>;
|
|
30
|
+
|
|
31
|
+
/** The sidebar every page is drawn in, which is the same for all of them and so says nothing of one. */
|
|
32
|
+
const NO_NAVIGATION: PreviewNavigation = { sections: [] };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* What draws `page` alone: its own state as the preview is sent it, minus
|
|
36
|
+
* the sidebar, and whether it reads real data. Another page changing, or
|
|
37
|
+
* the pages' order or titles, leaves the key as it was; changing the page
|
|
38
|
+
* itself, its theme or locale, or Real data does not.
|
|
39
|
+
*/
|
|
40
|
+
export function captureKey(page: MockupPageState, realData: boolean): string {
|
|
41
|
+
return JSON.stringify([
|
|
42
|
+
realData,
|
|
43
|
+
mockupPageRender(page, mockupDataTree(page, realData), NO_NAVIGATION),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The captures of each mockup, kept outside the viewer, which the dashboard
|
|
49
|
+
* builds again on a step of the browser's history, so a viewer built again,
|
|
50
|
+
* or another view of the mockup, can show a page the Overview drew.
|
|
51
|
+
*/
|
|
52
|
+
const stores = new Map<string, ShallowRef<PageCaptures>>();
|
|
53
|
+
|
|
54
|
+
function storeOf(name: string): ShallowRef<PageCaptures> {
|
|
55
|
+
const known = stores.get(name);
|
|
56
|
+
if (known) return known;
|
|
57
|
+
const made = shallowRef<PageCaptures>(new Map());
|
|
58
|
+
stores.set(name, made);
|
|
59
|
+
return made;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The captures of the mockup `name`, replaced as a whole on each change: read them reactively. */
|
|
63
|
+
export function mockupCaptures(name: string): Readonly<Ref<PageCaptures>> {
|
|
64
|
+
return storeOf(name);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The capture of `page` of the mockup `name`, stale or not; undefined while it has none. */
|
|
68
|
+
export function pageCapture(
|
|
69
|
+
name: string,
|
|
70
|
+
page: string,
|
|
71
|
+
): PageCapture | undefined {
|
|
72
|
+
return storeOf(name).value.get(page);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Keeps `image` as the capture of `page` of the mockup `name`, drawn from `key` at the height and with the blocks of `drawn`, and releases the image it replaces. */
|
|
76
|
+
export function storePageCapture(
|
|
77
|
+
name: string,
|
|
78
|
+
page: string,
|
|
79
|
+
key: string,
|
|
80
|
+
image: Blob,
|
|
81
|
+
drawn: CapturedLayout = {},
|
|
82
|
+
): void {
|
|
83
|
+
const store = storeOf(name);
|
|
84
|
+
const replaced = store.value.get(page);
|
|
85
|
+
store.value = new Map(store.value).set(page, {
|
|
86
|
+
key,
|
|
87
|
+
url: URL.createObjectURL(image),
|
|
88
|
+
...drawn,
|
|
89
|
+
});
|
|
90
|
+
if (replaced) URL.revokeObjectURL(replaced.url);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What the server holds of each mockup's first page as far as this browser
|
|
95
|
+
* session knows, as the page and the capture key it was sent from.
|
|
96
|
+
*/
|
|
97
|
+
const sent = new Map<string, string>();
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Takes the right to send the capture of `page`, drawn from `key`, as the
|
|
101
|
+
* image of the mockup `name`. False when it was sent already, or is being
|
|
102
|
+
* sent, so each drawing of a first page is sent once per session.
|
|
103
|
+
*/
|
|
104
|
+
export function claimCaptureUpload(
|
|
105
|
+
name: string,
|
|
106
|
+
page: string,
|
|
107
|
+
key: string,
|
|
108
|
+
): boolean {
|
|
109
|
+
const claim = JSON.stringify([page, key]);
|
|
110
|
+
if (sent.get(name) === claim) return false;
|
|
111
|
+
sent.set(name, claim);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Gives back a claim whose upload failed, so the same capture is sent again the next time it is current. */
|
|
116
|
+
export function releaseCaptureUpload(
|
|
117
|
+
name: string,
|
|
118
|
+
page: string,
|
|
119
|
+
key: string,
|
|
120
|
+
): void {
|
|
121
|
+
if (sent.get(name) === JSON.stringify([page, key])) sent.delete(name);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Forgets every capture of the mockup `name`, and releases its images. */
|
|
125
|
+
export function clearMockupCaptures(name: string): void {
|
|
126
|
+
sent.delete(name);
|
|
127
|
+
const store = storeOf(name);
|
|
128
|
+
for (const { url } of store.value.values()) URL.revokeObjectURL(url);
|
|
129
|
+
store.value = new Map();
|
|
130
|
+
}
|
|
@@ -152,17 +152,20 @@ export function mockupNavigation(
|
|
|
152
152
|
/**
|
|
153
153
|
* What the preview draws for a page of the mockup: `tree`, the page's own or
|
|
154
154
|
* its live one, in the page's theme, else the dashboard's, and its locale,
|
|
155
|
-
* inside `navigation`, under the page header its spec writes,
|
|
156
|
-
* `{{params.X}}` tokens filled with `params
|
|
155
|
+
* inside `navigation`, under the page header its spec writes, in the page's
|
|
156
|
+
* layout, its blocks' `{{params.X}}` tokens filled with `params`, and the
|
|
157
|
+
* page's URL query `query`.
|
|
157
158
|
*/
|
|
158
159
|
export function mockupPageRender(
|
|
159
160
|
page: MockupPageState,
|
|
160
161
|
tree: PreviewNode[],
|
|
161
162
|
navigation: PreviewNavigation,
|
|
162
163
|
params?: Record<string, string>,
|
|
164
|
+
query?: Record<string, string>,
|
|
163
165
|
): PreviewRenderMessage {
|
|
164
166
|
return previewRenderMessage({
|
|
165
167
|
...(params && { params }),
|
|
168
|
+
...(query && { query }),
|
|
166
169
|
tree,
|
|
167
170
|
theme: isPreviewTheme(page.options.theme)
|
|
168
171
|
? page.options.theme
|
|
@@ -176,5 +179,6 @@ export function mockupPageRender(
|
|
|
176
179
|
description: page.description,
|
|
177
180
|
actions: page.headerActions,
|
|
178
181
|
},
|
|
182
|
+
...(page.layout && { pageLayout: page.layout }),
|
|
179
183
|
});
|
|
180
184
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MockupPageState, readQueryValue } from "./mockup";
|
|
2
2
|
|
|
3
3
|
/** Where the viewer draws a mockup: a spec's `page:<id>` link compiles to it. */
|
|
4
4
|
export const MOCKUP_VIEWER_PATH = "/mockup";
|
|
@@ -8,6 +8,40 @@ const PAGE_QUERY = "page";
|
|
|
8
8
|
/** The viewer's query naming the row a page with a route shows. */
|
|
9
9
|
export const RECORD_QUERY = "record";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The query parameters the viewer and its preview read themselves: the
|
|
13
|
+
* mockup, the page, the canvas width, the data shown, the preview's state and
|
|
14
|
+
* its fixtures-only switch.
|
|
15
|
+
*/
|
|
16
|
+
const VIEWER_QUERY_KEYS: ReadonlySet<string> = new Set([
|
|
17
|
+
"name",
|
|
18
|
+
PAGE_QUERY,
|
|
19
|
+
"width",
|
|
20
|
+
"data",
|
|
21
|
+
"state",
|
|
22
|
+
"fixtures",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The query of the page the viewer shows, which its tables'
|
|
27
|
+
* `queryParamFilters` and its `{{query.X}}` tokens read: the viewer's URL
|
|
28
|
+
* query, `?record=` included, without the parameters the viewer reads
|
|
29
|
+
* itself. None when nothing is left.
|
|
30
|
+
*/
|
|
31
|
+
export function mockupPageQuery(
|
|
32
|
+
query: Readonly<
|
|
33
|
+
Record<string, string | null | readonly (string | null)[] | undefined>
|
|
34
|
+
>,
|
|
35
|
+
): Record<string, string> | undefined {
|
|
36
|
+
const entries = Object.entries(query).flatMap(([key, value]) => {
|
|
37
|
+
const read = readQueryValue(value);
|
|
38
|
+
return VIEWER_QUERY_KEYS.has(key) || read === undefined
|
|
39
|
+
? []
|
|
40
|
+
: [[key, read] as const];
|
|
41
|
+
});
|
|
42
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
11
45
|
/** A page of the mockup a link opens, and the row it shows there. */
|
|
12
46
|
export interface MockupLink {
|
|
13
47
|
page: string;
|
|
@@ -327,34 +327,61 @@ function overlaps(left: PreviewRect, right: PreviewRect): boolean {
|
|
|
327
327
|
);
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
+
/** How wide a frame is on the screen, at least, for its page to be worth drawing live: a narrower frame is a thumbnail, which its image serves as well. */
|
|
331
|
+
export const LIVE_FRAME_MIN_SCREEN_WIDTH = 400;
|
|
332
|
+
|
|
333
|
+
/** What decides which pages the live slots draw. */
|
|
334
|
+
export interface LiveView {
|
|
335
|
+
frames: readonly OverviewFrame[];
|
|
336
|
+
camera: OverviewCamera;
|
|
337
|
+
viewport: ViewportSize;
|
|
338
|
+
/** The page picked with a click, if any. */
|
|
339
|
+
picked: string | undefined;
|
|
340
|
+
/** Whether the page has no image, or one that is out of date. */
|
|
341
|
+
needsCapture: (page: string) => boolean;
|
|
342
|
+
}
|
|
343
|
+
|
|
330
344
|
/**
|
|
331
|
-
* The
|
|
332
|
-
*
|
|
345
|
+
* The pages to draw live, most wanted first: the picked page; the frames in
|
|
346
|
+
* view, while a frame is at least {@link LIVE_FRAME_MIN_SCREEN_WIDTH} wide on
|
|
347
|
+
* the screen, those with no current image before the others, each group
|
|
348
|
+
* nearest the middle of the view first; then every page with no current
|
|
349
|
+
* image, nearest first. A page in view with no image comes before the pages
|
|
350
|
+
* in view that have one, so a view of more frames than slots still draws and
|
|
351
|
+
* captures each of them. The caller hands slots to the first few.
|
|
333
352
|
*/
|
|
334
|
-
export function
|
|
335
|
-
frames
|
|
336
|
-
camera
|
|
337
|
-
viewport
|
|
338
|
-
|
|
353
|
+
export function wantedLivePages({
|
|
354
|
+
frames,
|
|
355
|
+
camera,
|
|
356
|
+
viewport,
|
|
357
|
+
picked,
|
|
358
|
+
needsCapture,
|
|
359
|
+
}: LiveView): string[] {
|
|
339
360
|
const width = viewport.width / camera.zoom;
|
|
340
361
|
const height = viewport.height / camera.zoom;
|
|
341
362
|
const { x, y } = toWorld(camera, { x: 0, y: 0 });
|
|
342
|
-
const
|
|
343
|
-
x: x - width / 2,
|
|
344
|
-
y: y - height / 2,
|
|
345
|
-
width: width * 2,
|
|
346
|
-
height: height * 2,
|
|
347
|
-
};
|
|
363
|
+
const view = { x, y, width, height };
|
|
348
364
|
const middle = { x: x + width / 2, y: y + height / 2 };
|
|
349
365
|
const distance = ({ rect }: OverviewFrame) =>
|
|
350
366
|
Math.hypot(
|
|
351
367
|
rect.x + rect.width / 2 - middle.x,
|
|
352
368
|
rect.y + rect.height / 2 - middle.y,
|
|
353
369
|
);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
370
|
+
const nearest = [...frames].sort((a, b) => distance(a) - distance(b));
|
|
371
|
+
const isWide =
|
|
372
|
+
OVERVIEW_FRAME_WIDTH * camera.zoom >= LIVE_FRAME_MIN_SCREEN_WIDTH;
|
|
373
|
+
const inView = isWide
|
|
374
|
+
? nearest.filter(({ rect }) => overlaps(rect, view)).map(({ id }) => id)
|
|
375
|
+
: [];
|
|
376
|
+
const wanted = [
|
|
377
|
+
...(picked !== undefined && frames.some(({ id }) => id === picked)
|
|
378
|
+
? [picked]
|
|
379
|
+
: []),
|
|
380
|
+
...inView.filter(needsCapture),
|
|
381
|
+
...inView.filter((id) => !needsCapture(id)),
|
|
382
|
+
...nearest.map(({ id }) => id).filter(needsCapture),
|
|
383
|
+
];
|
|
384
|
+
return [...new Set(wanted)];
|
|
358
385
|
}
|
|
359
386
|
|
|
360
387
|
/**
|