@fc3/mmcadi 0.1.0
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/LICENSE +673 -0
- package/README.md +5 -0
- package/bin/compile +63 -0
- package/bin/copy-static-files +13 -0
- package/bin/install +5 -0
- package/bin/precompile +55 -0
- package/bin/prepublish +7 -0
- package/bin/remap-paths +113 -0
- package/bin/test +9 -0
- package/config/tsconfig.json +37 -0
- package/package.json +33 -0
- package/src/bootstrap/start.ts +12 -0
- package/src/client/bootstrap.ts +5 -0
- package/src/client/client.ts +54 -0
- package/src/client/enum/key-code.ts +34 -0
- package/src/client/enum/page-type.ts +19 -0
- package/src/client/factory/page.ts +61 -0
- package/src/client/page/confirm-delete-block.ts +30 -0
- package/src/client/page/create-block.ts +6 -0
- package/src/client/page/day.ts +8 -0
- package/src/client/page/edit-block.ts +43 -0
- package/src/client/page/edit-custom.ts +16 -0
- package/src/client/page/home.ts +8 -0
- package/src/client/page/login.ts +8 -0
- package/src/client/page/logout.ts +8 -0
- package/src/client/page/month.ts +8 -0
- package/src/client/page/move-block.ts +8 -0
- package/src/client/page/select-block-type.ts +56 -0
- package/src/client/page/settings.ts +8 -0
- package/src/client/page/view-custom.ts +665 -0
- package/src/client/page/week.ts +8 -0
- package/src/client/page/year.ts +8 -0
- package/src/client/page.ts +128 -0
- package/src/client/shim/execute.ts +5 -0
- package/src/client/shim/logger.ts +44 -0
- package/src/client/utility/get-meta-value.ts +23 -0
- package/src/common/builder/block/background.ts +25 -0
- package/src/common/builder/block/folder.ts +43 -0
- package/src/common/builder/block/header.ts +15 -0
- package/src/common/builder/block/link.ts +32 -0
- package/src/common/builder/block/multicolumn.ts +16 -0
- package/src/common/builder/block/note.ts +13 -0
- package/src/common/builder/block/whitespace.ts +13 -0
- package/src/common/utility/get-parent-path.ts +29 -0
- package/src/constant/month-names.ts +16 -0
- package/src/enum/action-type.ts +11 -0
- package/src/enum/block-type.ts +18 -0
- package/src/enum/calendar-view-mode.ts +9 -0
- package/src/enum/color.ts +15 -0
- package/src/enum/default-role.ts +6 -0
- package/src/enum/directory-item-type.ts +6 -0
- package/src/enum/emoji.ts +94 -0
- package/src/enum/field-type.ts +8 -0
- package/src/enum/header-size.ts +7 -0
- package/src/enum/permission-type.ts +8 -0
- package/src/enum/time-place-visibility.ts +8 -0
- package/src/enum/tool-type.ts +14 -0
- package/src/index.ts +8 -0
- package/src/interface/hydration-callback.ts +7 -0
- package/src/interface/provider.ts +8 -0
- package/src/interface/repository.ts +12 -0
- package/src/lib/array/add.ts +10 -0
- package/src/lib/array/assert-is-empty.ts +23 -0
- package/src/lib/array/clone.ts +5 -0
- package/src/lib/array/difference.ts +8 -0
- package/src/lib/array/empty.ts +6 -0
- package/src/lib/array/equal.ts +24 -0
- package/src/lib/array/get-first-value.ts +5 -0
- package/src/lib/array/get-last-value.ts +5 -0
- package/src/lib/array/get-max-value.ts +5 -0
- package/src/lib/array/get-value-after.ts +23 -0
- package/src/lib/array/get-value-before.ts +23 -0
- package/src/lib/array/get-values-between.ts +18 -0
- package/src/lib/array/index.ts +5 -0
- package/src/lib/array/is-empty.ts +6 -0
- package/src/lib/array/remove.ts +19 -0
- package/src/lib/array/sum.ts +11 -0
- package/src/lib/array/unique.ts +13 -0
- package/src/lib/environment/bootstrap.ts +1 -0
- package/src/lib/environment/enum/environment-type.ts +8 -0
- package/src/lib/environment/enum/service-type.ts +5 -0
- package/src/lib/environment/index.ts +7 -0
- package/src/lib/environment/utility/get-environment-type.ts +28 -0
- package/src/lib/environment/utility/is-browser.ts +5 -0
- package/src/lib/environment/utility/is-development.ts +10 -0
- package/src/lib/environment/utility/is-production-or-staging.ts +8 -0
- package/src/lib/environment/utility/is-production.ts +10 -0
- package/src/lib/environment/utility/is-staging.ts +10 -0
- package/src/lib/errors/enum/error-type.ts +13 -0
- package/src/lib/errors/error/base.ts +40 -0
- package/src/lib/errors/error/conflict.ts +16 -0
- package/src/lib/errors/error/generic.ts +23 -0
- package/src/lib/errors/error/invalid.ts +14 -0
- package/src/lib/errors/error/invariant-violation.ts +5 -0
- package/src/lib/errors/error/not-allowed.ts +14 -0
- package/src/lib/errors/error/not-found.ts +16 -0
- package/src/lib/errors/error/not-implemented.ts +20 -0
- package/src/lib/errors/error/omitted.ts +14 -0
- package/src/lib/errors/error/timeout.ts +14 -0
- package/src/lib/errors/error/unauthorized.ts +14 -0
- package/src/lib/errors/index.ts +18 -0
- package/src/lib/errors/sugar/invariant.ts +7 -0
- package/src/lib/errors/type/coded-error.ts +7 -0
- package/src/lib/errors/type/error-data.ts +11 -0
- package/src/lib/errors/utility/create-error-for-error-type.ts +60 -0
- package/src/lib/errors/utility/create-error-from-ambiguous-json-data.ts +26 -0
- package/src/lib/errors/utility/error-matches.ts +28 -0
- package/src/lib/errors/utility/get-error-type-for-posix-error-code.ts +37 -0
- package/src/lib/errors/utility/get-error-type-for-status-code.ts +38 -0
- package/src/lib/errors/utility/get-message-for-error-type.ts +29 -0
- package/src/lib/errors/utility/matches-posix-error-code.ts +11 -0
- package/src/lib/errors/utility/wrap-error.ts +39 -0
- package/src/lib/event-emitter/index.ts +63 -0
- package/src/lib/execution-context/execution-context.ts +90 -0
- package/src/lib/execution-context/index.ts +8 -0
- package/src/lib/execution-context/type/session.ts +7 -0
- package/src/lib/feature/feature.ts +108 -0
- package/src/lib/feature/index.ts +3 -0
- package/src/lib/filesystem/bootstrap.ts +1 -0
- package/src/lib/filesystem/enum/file-extension.ts +19 -0
- package/src/lib/filesystem/index.ts +4 -0
- package/src/lib/filesystem/utility/exists.ts +21 -0
- package/src/lib/filesystem/utility/get-extension-for-filepath.ts +20 -0
- package/src/lib/filesystem/utility/strip-extension.ts +26 -0
- package/src/lib/grammar/index.ts +3 -0
- package/src/lib/grammar/noun-inflector.ts +104 -0
- package/src/lib/grammar/utility/get-words-from-identifier.ts +9 -0
- package/src/lib/grammar/verb-inflector.ts +344 -0
- package/src/lib/http/buffer-stream.ts +76 -0
- package/src/lib/http/enum/content-type.ts +19 -0
- package/src/lib/http/enum/cookie-attribute.ts +11 -0
- package/src/lib/http/enum/header.ts +29 -0
- package/src/lib/http/enum/method.ts +11 -0
- package/src/lib/http/enum/same-site-policy.ts +7 -0
- package/src/lib/http/enum/status-code.ts +9 -0
- package/src/lib/http/factory/body-parser.ts +55 -0
- package/src/lib/http/index.ts +24 -0
- package/src/lib/http/interface/client-request.ts +15 -0
- package/src/lib/http/interface/incoming-message.ts +24 -0
- package/src/lib/http/interface/network-library.ts +9 -0
- package/src/lib/http/interface/request-callback.ts +7 -0
- package/src/lib/http/isomorphic/request.ts +77 -0
- package/src/lib/http/isomorphic/response.ts +77 -0
- package/src/lib/http/isomorphic.ts +20 -0
- package/src/lib/http/parser/accept-header.ts +35 -0
- package/src/lib/http/parser/basic-auth-header.ts +48 -0
- package/src/lib/http/parser/body/json.ts +14 -0
- package/src/lib/http/parser/body/multipart.ts +89 -0
- package/src/lib/http/parser/body/url-encoded.ts +16 -0
- package/src/lib/http/parser/body.ts +44 -0
- package/src/lib/http/parser/cookie.ts +114 -0
- package/src/lib/http/parser/querystring.ts +92 -0
- package/src/lib/http/parser/url.ts +76 -0
- package/src/lib/http/request/incoming.ts +299 -0
- package/src/lib/http/request/outgoing.ts +276 -0
- package/src/lib/http/request.ts +26 -0
- package/src/lib/http/response/incoming.ts +243 -0
- package/src/lib/http/response/outgoing.ts +160 -0
- package/src/lib/http/response.ts +74 -0
- package/src/lib/http/serializer/basic-auth-header.ts +27 -0
- package/src/lib/http/serializer/cookie.ts +90 -0
- package/src/lib/http/serializer/query-data.ts +54 -0
- package/src/lib/http/transaction.ts +320 -0
- package/src/lib/http/type/basic-auth-credentials.ts +6 -0
- package/src/lib/http/type/header-map.ts +5 -0
- package/src/lib/http/type/log-attributes.ts +12 -0
- package/src/lib/http/type/path-parameters.ts +5 -0
- package/src/lib/http/type/query-data.ts +7 -0
- package/src/lib/http/type/query-value.ts +11 -0
- package/src/lib/http/type/request-options.ts +16 -0
- package/src/lib/http/type/transaction-data.ts +4 -0
- package/src/lib/http/utility/get-content-type-for-extension.ts +47 -0
- package/src/lib/http/utility/get-library-for-protocol.ts +25 -0
- package/src/lib/http/utility/get-status-code-for-error-type.ts +37 -0
- package/src/lib/http/utility/get-status-code-for-error.ts +13 -0
- package/src/lib/http/utility/is-client-error-status.ts +15 -0
- package/src/lib/http/utility/is-error-status.ts +9 -0
- package/src/lib/http/utility/is-server-error-status.ts +7 -0
- package/src/lib/http/utility/is-success-status.ts +7 -0
- package/src/lib/http/utility/proxy-request.ts +58 -0
- package/src/lib/http/utility/serialize-request-options.ts +9 -0
- package/src/lib/http/utility/slug-generator.ts +20 -0
- package/src/lib/key-generator/index.ts +3 -0
- package/src/lib/key-generator/key-generator.ts +7 -0
- package/src/lib/logger/enum/ansi-escape-code.ts +14 -0
- package/src/lib/logger/enum/log-level.ts +8 -0
- package/src/lib/logger/formatter.ts +59 -0
- package/src/lib/logger/index.ts +7 -0
- package/src/lib/logger/interface/error-reporter.ts +7 -0
- package/src/lib/logger/interface/logger.ts +13 -0
- package/src/lib/logger/logger.ts +239 -0
- package/src/lib/logger/type/error-parameters.ts +9 -0
- package/src/lib/logger/type/loggable-data.ts +5 -0
- package/src/lib/logger/type/loggable-value.ts +1 -0
- package/src/lib/metrics/dispatcher.ts +264 -0
- package/src/lib/metrics/enum/dispatch-mode.ts +6 -0
- package/src/lib/metrics/index.ts +2 -0
- package/src/lib/metrics/settings-hydrator.ts +51 -0
- package/src/lib/metrics/type/dispatcher-settings.ts +12 -0
- package/src/lib/metrics/type/tag-map.ts +5 -0
- package/src/lib/network/bootstrap.ts +1 -0
- package/src/lib/network/enum/connection-status.ts +14 -0
- package/src/lib/network/enum/http-status-code.ts +75 -0
- package/src/lib/network/enum/network-protocol.ts +10 -0
- package/src/lib/network/event-emitter.ts +63 -0
- package/src/lib/network/index.ts +7 -0
- package/src/lib/network/interface/socket.ts +42 -0
- package/src/lib/network/type/socket-options.ts +6 -0
- package/src/lib/network/utility/get-protocol-from-url.ts +15 -0
- package/src/lib/operation/index.ts +6 -0
- package/src/lib/operation/operation/auto-logging.ts +94 -0
- package/src/lib/operation/operation/silent.ts +17 -0
- package/src/lib/operation/operation.ts +80 -0
- package/src/lib/process/bootstrap.ts +1 -0
- package/src/lib/process/enum/posix-error-code.ts +138 -0
- package/src/lib/process/enum/process-signal.ts +68 -0
- package/src/lib/process/error.ts +6 -0
- package/src/lib/process/execute.ts +77 -0
- package/src/lib/process/index.ts +4 -0
- package/src/lib/process/type/command-options.ts +9 -0
- package/src/lib/process/utility/bind-process-lifespan-to.ts +10 -0
- package/src/lib/promise-wrapper/index.ts +3 -0
- package/src/lib/promise-wrapper/promise-wrapper.ts +51 -0
- package/src/lib/random/chance.ts +5 -0
- package/src/lib/random/element.ts +7 -0
- package/src/lib/random/elements.ts +12 -0
- package/src/lib/random/enum.ts +34 -0
- package/src/lib/random/enums.ts +11 -0
- package/src/lib/random/index.ts +3 -0
- package/src/lib/random/number.ts +8 -0
- package/src/lib/server/base.ts +194 -0
- package/src/lib/server/enum/server-event.ts +5 -0
- package/src/lib/server/enum/server-status.ts +10 -0
- package/src/lib/server/http/endpoint/ping.ts +21 -0
- package/src/lib/server/http/endpoint.ts +345 -0
- package/src/lib/server/http/interface/endpoint-constructor.ts +12 -0
- package/src/lib/server/http/interface/result-serializer.ts +5 -0
- package/src/lib/server/http/middleware.ts +18 -0
- package/src/lib/server/http/result-serializer/html.ts +92 -0
- package/src/lib/server/http/result-serializer/json.ts +23 -0
- package/src/lib/server/http/route.ts +104 -0
- package/src/lib/server/http/router.ts +125 -0
- package/src/lib/server/http/type/session-resolver.ts +8 -0
- package/src/lib/server/http/utility/create-server.ts +34 -0
- package/src/lib/server/http/utility/path-parser.ts +49 -0
- package/src/lib/server/http/utility/standardize-html-indentation.ts +54 -0
- package/src/lib/server/http/websocket-wrapper.ts +83 -0
- package/src/lib/server/http.ts +301 -0
- package/src/lib/server/index.ts +5 -0
- package/src/lib/server/tcp.ts +53 -0
- package/src/lib/server/type/server-options.ts +10 -0
- package/src/lib/string/calculate-length.ts +17 -0
- package/src/lib/string/capitalize.ts +8 -0
- package/src/lib/string/create-slug.ts +14 -0
- package/src/lib/string/enum/ansi-escape-code.ts +14 -0
- package/src/lib/string/enum/string-encoding.ts +9 -0
- package/src/lib/string/hyphenate.ts +5 -0
- package/src/lib/string/index.ts +3 -0
- package/src/lib/string/pad.ts +14 -0
- package/src/lib/string/trim-multiline.ts +21 -0
- package/src/lib/string/trim.ts +8 -0
- package/src/lib/tcp/channel.ts +13 -0
- package/src/lib/tcp/connection/incoming.ts +72 -0
- package/src/lib/tcp/connection/outgoing.ts +219 -0
- package/src/lib/tcp/connection.ts +360 -0
- package/src/lib/tcp/enum/connection-event.ts +12 -0
- package/src/lib/tcp/enum/message-type.ts +9 -0
- package/src/lib/tcp/index.ts +1 -0
- package/src/lib/tcp/type/connection-parameters.ts +6 -0
- package/src/lib/tcp/type/message/channel-close.ts +9 -0
- package/src/lib/tcp/type/message/channel-open.ts +9 -0
- package/src/lib/tcp/type/message.ts +10 -0
- package/src/lib/test/index.ts +2 -0
- package/src/lib/test/utility/build-config.ts +17 -0
- package/src/lib/test/utility/build-execution-context.ts +11 -0
- package/src/lib/time/bootstrap.ts +1 -0
- package/src/lib/time/enum/time-interval.ts +12 -0
- package/src/lib/time/index.ts +4 -0
- package/src/lib/time/utility/format-duration.ts +139 -0
- package/src/lib/time/utility/format-relative-duration.ts +22 -0
- package/src/lib/time/utility/sleep.ts +9 -0
- package/src/operation.ts +18 -0
- package/src/server/endpoint/abstract-page.ts +126 -0
- package/src/server/endpoint/action/create.ts +545 -0
- package/src/server/endpoint/action/get.ts +231 -0
- package/src/server/endpoint/base.ts +51 -0
- package/src/server/endpoint/day.ts +13 -0
- package/src/server/endpoint/generic-page.ts +14 -0
- package/src/server/endpoint/index.ts +11 -0
- package/src/server/endpoint/login.ts +45 -0
- package/src/server/endpoint/logout.ts +38 -0
- package/src/server/endpoint/month.ts +35 -0
- package/src/server/endpoint/robots.ts +18 -0
- package/src/server/endpoint/session/create.ts +62 -0
- package/src/server/endpoint/settings/get.ts +40 -0
- package/src/server/endpoint/settings/update.ts +44 -0
- package/src/server/endpoint/today.ts +15 -0
- package/src/server/endpoint/week.ts +34 -0
- package/src/server/endpoint/year.ts +34 -0
- package/src/server/enum/custom-page-type.ts +10 -0
- package/src/server/factory/block-result-serializer.ts +115 -0
- package/src/server/middleware/base.ts +6 -0
- package/src/server/middleware/error-handler.ts +177 -0
- package/src/server/middleware/static-file.ts +83 -0
- package/src/server/operation/add-block.ts +110 -0
- package/src/server/operation/create-session.ts +43 -0
- package/src/server/operation/delete-block.ts +96 -0
- package/src/server/operation/demote-block.ts +108 -0
- package/src/server/operation/destroy-session.ts +26 -0
- package/src/server/operation/load-account.ts +30 -0
- package/src/server/operation/load-block.ts +48 -0
- package/src/server/operation/load-directory-items.ts +75 -0
- package/src/server/operation/load-page.ts +368 -0
- package/src/server/operation/promote-block.ts +104 -0
- package/src/server/operation/save-page.ts +60 -0
- package/src/server/operation/update-account-settings.ts +52 -0
- package/src/server/operation/update-block.ts +124 -0
- package/src/server/repository/memory.ts +112 -0
- package/src/server/result-serializer/action.ts +939 -0
- package/src/server/result-serializer/base.ts +1267 -0
- package/src/server/result-serializer/block/audio.ts +33 -0
- package/src/server/result-serializer/block/background.ts +20 -0
- package/src/server/result-serializer/block/calendar.ts +148 -0
- package/src/server/result-serializer/block/directory.ts +57 -0
- package/src/server/result-serializer/block/ephemeral.ts +14 -0
- package/src/server/result-serializer/block/folder.ts +106 -0
- package/src/server/result-serializer/block/header.ts +31 -0
- package/src/server/result-serializer/block/image.ts +46 -0
- package/src/server/result-serializer/block/link.ts +40 -0
- package/src/server/result-serializer/block/list.ts +140 -0
- package/src/server/result-serializer/block/multi-column.ts +97 -0
- package/src/server/result-serializer/block/note.ts +44 -0
- package/src/server/result-serializer/block/todo.ts +78 -0
- package/src/server/result-serializer/block/whitespace.ts +15 -0
- package/src/server/result-serializer/block.ts +248 -0
- package/src/server/result-serializer/common/time-place-options.ts +33 -0
- package/src/server/result-serializer/login.ts +58 -0
- package/src/server/result-serializer/month.ts +170 -0
- package/src/server/result-serializer/page.ts +548 -0
- package/src/server/result-serializer/settings.ts +85 -0
- package/src/server/result-serializer/week.ts +195 -0
- package/src/server/result-serializer/year.ts +160 -0
- package/src/server/utility/accepts-content-type.ts +16 -0
- package/src/server/utility/accepts-html.ts +9 -0
- package/src/server/utility/accepts-json.ts +9 -0
- package/src/server/utility/add-days.ts +11 -0
- package/src/server/utility/create-date.ts +23 -0
- package/src/server/utility/create-index-path.ts +5 -0
- package/src/server/utility/create-slug.ts +9 -0
- package/src/server/utility/create-toast-path.ts +19 -0
- package/src/server/utility/date-less-than.ts +5 -0
- package/src/server/utility/date-occurs-before.ts +22 -0
- package/src/server/utility/date-to-key.ts +7 -0
- package/src/server/utility/date-to-label.ts +5 -0
- package/src/server/utility/date-to-path.ts +9 -0
- package/src/server/utility/dates-are-equal.ts +22 -0
- package/src/server/utility/dates-are-in-order.ts +9 -0
- package/src/server/utility/dates-are-on-the-same-day.ts +9 -0
- package/src/server/utility/dates-in-same-month.ts +8 -0
- package/src/server/utility/day-to-date.ts +40 -0
- package/src/server/utility/decrement-date.ts +11 -0
- package/src/server/utility/get-block-at-index-path.ts +32 -0
- package/src/server/utility/get-block-permissions.ts +15 -0
- package/src/server/utility/get-compact-label-for-date.ts +8 -0
- package/src/server/utility/get-custom-page-type-for-path.ts +37 -0
- package/src/server/utility/get-element-id-for-block.ts +15 -0
- package/src/server/utility/get-emoji-for-block-type.ts +39 -0
- package/src/server/utility/get-emoji-for-tool-type.ts +20 -0
- package/src/server/utility/get-end-of-month.ts +13 -0
- package/src/server/utility/get-end-of-week.ts +13 -0
- package/src/server/utility/get-filepath-for-folder-block.ts +23 -0
- package/src/server/utility/get-hex-for-color.ts +31 -0
- package/src/server/utility/get-label-for-time-place-visibility.ts +23 -0
- package/src/server/utility/get-month-name.ts +18 -0
- package/src/server/utility/get-next-day.ts +7 -0
- package/src/server/utility/get-next-month.ts +12 -0
- package/src/server/utility/get-next-week.ts +12 -0
- package/src/server/utility/get-next-year.ts +13 -0
- package/src/server/utility/get-ordinal-label-for-week.ts +11 -0
- package/src/server/utility/get-ordinal-of-week-within-month.ts +15 -0
- package/src/server/utility/get-padded-date.ts +11 -0
- package/src/server/utility/get-parent-index-path.ts +18 -0
- package/src/server/utility/get-path-for-folder-block.ts +25 -0
- package/src/server/utility/get-path-from-url.ts +13 -0
- package/src/server/utility/get-previous-index-path.ts +27 -0
- package/src/server/utility/get-previous-month.ts +12 -0
- package/src/server/utility/get-previous-week.ts +11 -0
- package/src/server/utility/get-previous-year.ts +13 -0
- package/src/server/utility/get-random-emoji-for-date.ts +109 -0
- package/src/server/utility/get-short-label-for-date.ts +11 -0
- package/src/server/utility/get-short-month-name.ts +9 -0
- package/src/server/utility/get-short-ordinal.ts +26 -0
- package/src/server/utility/get-siblings-and-index-for-index-path.ts +67 -0
- package/src/server/utility/get-start-of-month.ts +11 -0
- package/src/server/utility/get-start-of-week.ts +12 -0
- package/src/server/utility/get-start-of-year.ts +12 -0
- package/src/server/utility/get-weekday-name.ts +24 -0
- package/src/server/utility/increment-date.ts +15 -0
- package/src/server/utility/is-index-path.ts +5 -0
- package/src/server/utility/key-to-date.ts +25 -0
- package/src/server/utility/month-has-week-containing-date.ts +13 -0
- package/src/server/utility/month-to-date.ts +28 -0
- package/src/server/utility/month-to-path.ts +10 -0
- package/src/server/utility/months-are-equal.ts +8 -0
- package/src/server/utility/parse-index-path.ts +23 -0
- package/src/server/utility/path-is-date.ts +13 -0
- package/src/server/utility/path-to-date.ts +24 -0
- package/src/server/utility/subtract-days.ts +7 -0
- package/src/server/utility/validate-month.ts +10 -0
- package/src/server/utility/validate-page.ts +46 -0
- package/src/server/utility/validate-path.ts +9 -0
- package/src/server/utility/validate-url.ts +12 -0
- package/src/server/utility/week-greater-than.ts +10 -0
- package/src/server/utility/week-to-date.ts +8 -0
- package/src/server/utility/week-to-path.ts +12 -0
- package/src/server/utility/weeks-are-equal.ts +8 -0
- package/src/server/utility/year-to-date.ts +26 -0
- package/src/server/utility/year-to-path.ts +7 -0
- package/src/server/utility/years-are-equal.ts +8 -0
- package/src/server.ts +140 -0
- package/src/test.ts +195 -0
- package/src/type/account-settings.ts +9 -0
- package/src/type/account.ts +11 -0
- package/src/type/action/add-block.ts +74 -0
- package/src/type/action/complete-block.ts +10 -0
- package/src/type/action/delete-block.ts +11 -0
- package/src/type/action/demote-block.ts +9 -0
- package/src/type/action/edit-block.ts +11 -0
- package/src/type/action/promote-block.ts +9 -0
- package/src/type/action.ts +9 -0
- package/src/type/block/audio.ts +8 -0
- package/src/type/block/background.ts +10 -0
- package/src/type/block/directory.ts +18 -0
- package/src/type/block/ephemeral.ts +9 -0
- package/src/type/block/folder.ts +14 -0
- package/src/type/block/header.ts +11 -0
- package/src/type/block/image.ts +8 -0
- package/src/type/block/link.ts +12 -0
- package/src/type/block/list.ts +24 -0
- package/src/type/block/multi-column.ts +10 -0
- package/src/type/block/note.ts +9 -0
- package/src/type/block/todo.ts +10 -0
- package/src/type/block/whitespace.ts +9 -0
- package/src/type/block-metadata.ts +14 -0
- package/src/type/block.ts +18 -0
- package/src/type/day.ts +5 -0
- package/src/type/field-definition.ts +8 -0
- package/src/type/field-value.ts +5 -0
- package/src/type/file.ts +6 -0
- package/src/type/month.ts +5 -0
- package/src/type/page.ts +8 -0
- package/src/type/price.ts +11 -0
- package/src/type/resource.ts +5 -0
- package/src/type/runtime-config.ts +13 -0
- package/src/type/server-settings.ts +17 -0
- package/src/type/toast.ts +8 -0
- package/src/type/week.ts +5 -0
- package/src/type/year.ts +5 -0
- package/test/unit/index.ts +11 -0
- package/test/unit/server/operation/promote-block.ts +84 -0
package/bin/compile
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
if [[ $1 == '--help' ]]; then
|
|
4
|
+
echo "Triggers recompilation of the source code for the current project."
|
|
5
|
+
echo "Supported flags:"
|
|
6
|
+
echo "--force : Bypasses any precompilation checks (cache, mutex, etc)"
|
|
7
|
+
echo " Use this if you want to recompile no matter what."
|
|
8
|
+
echo " "
|
|
9
|
+
exit 0
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
if [[ $1 != '--force' ]]; then
|
|
13
|
+
./bin/precompile
|
|
14
|
+
|
|
15
|
+
case $? in
|
|
16
|
+
1)
|
|
17
|
+
exit 1
|
|
18
|
+
;;
|
|
19
|
+
3)
|
|
20
|
+
exit 0
|
|
21
|
+
;;
|
|
22
|
+
esac
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
echo "Recompiling..."
|
|
26
|
+
mkdir -p dist
|
|
27
|
+
echo $$ > dist/.compile-lock
|
|
28
|
+
rm -f dist/.last-compile-time
|
|
29
|
+
|
|
30
|
+
project_dir="$(dirname $(dirname "$0"))"
|
|
31
|
+
|
|
32
|
+
if [[ $1 == '--force' ]]; then
|
|
33
|
+
rm -rf dist/src
|
|
34
|
+
rm -rf dist/test
|
|
35
|
+
./node_modules/.bin/tsc --declaration --project "$project_dir/config/tsconfig.json"
|
|
36
|
+
else
|
|
37
|
+
./node_modules/.bin/tsc --declaration --incremental --project "$project_dir/config/tsconfig.json"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
exit_status=$?
|
|
41
|
+
|
|
42
|
+
if [[ $exit_status -eq 0 ]]; then
|
|
43
|
+
./bin/remap-paths
|
|
44
|
+
./bin/copy-static-files
|
|
45
|
+
echo $(date +%s) > dist/.last-compile-time
|
|
46
|
+
|
|
47
|
+
./node_modules/.bin/esbuild "$project_dir/src/client/bootstrap.ts" \
|
|
48
|
+
--bundle \
|
|
49
|
+
--tsconfig="$project_dir/config/tsconfig.json" \
|
|
50
|
+
--outfile="$project_dir/dist/client.js" \
|
|
51
|
+
--alias:lib/logger/logger=client/shim/logger.ts \
|
|
52
|
+
--alias:lib/process/execute=client/shim/execute.ts
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
pid=$(cat dist/.compile-lock)
|
|
56
|
+
|
|
57
|
+
if [[ $pid == $$ ]]; then
|
|
58
|
+
rm dist/.compile-lock
|
|
59
|
+
exit $exit_status
|
|
60
|
+
else
|
|
61
|
+
echo "Detected a conflicting compile lock..."
|
|
62
|
+
exit 1
|
|
63
|
+
fi
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
echo "Copying static files to dist..."
|
|
6
|
+
|
|
7
|
+
find "src" -type f ! -name '*.ts' | while read -r file; do
|
|
8
|
+
# Ignore vim swapfiles too:
|
|
9
|
+
if [[ ! "$file" == *"swp"* ]]; then
|
|
10
|
+
echo "$file --> dist/$file"
|
|
11
|
+
cp "$file" "dist/$file"
|
|
12
|
+
fi
|
|
13
|
+
done
|
package/bin/install
ADDED
package/bin/precompile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
mkdir -p dist
|
|
4
|
+
|
|
5
|
+
if [ -f dist/.compile-lock ]; then
|
|
6
|
+
pid=$(cat dist/.compile-lock)
|
|
7
|
+
ticks=0
|
|
8
|
+
max_ticks=10
|
|
9
|
+
|
|
10
|
+
if ! ps -p $pid > /dev/null; then
|
|
11
|
+
echo "Detected a stale compile lock; deleting..."
|
|
12
|
+
rm -f dist/.compile-lock
|
|
13
|
+
else
|
|
14
|
+
echo "Compilation already in progress; waiting up to $max_ticks seconds..."
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
while [ -f dist/.compile-lock ]; do
|
|
18
|
+
sleep 1
|
|
19
|
+
let ticks=ticks+1
|
|
20
|
+
|
|
21
|
+
if [ $ticks -ge $max_ticks ]; then
|
|
22
|
+
echo "Timed out waiting for compilation to clear"
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
done
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
if [[ -f ./dist/.last-publish-time ]]; then
|
|
29
|
+
echo "Found publication compile artifact; skipping recompilation."
|
|
30
|
+
exit 3
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
if [ -f dist/.last-compile-time ]; then
|
|
34
|
+
if [ ! -d src ]; then
|
|
35
|
+
# TODO: Confirm we're within a deploy environment
|
|
36
|
+
echo "src folder does not exist; skipping recompilation."
|
|
37
|
+
exit 3
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
typeset -i last_modification_time=$(find src test -type f -print0 |
|
|
41
|
+
xargs -0 stat -c "%X %N" |
|
|
42
|
+
sort -rn |
|
|
43
|
+
head -1 |
|
|
44
|
+
awk '{ print $1 }')
|
|
45
|
+
|
|
46
|
+
typeset -i last_compile_time=$(cat dist/.last-compile-time)
|
|
47
|
+
|
|
48
|
+
if (( $last_compile_time > $last_modification_time )); then
|
|
49
|
+
echo "No changes since last compile; skipping recompilation."
|
|
50
|
+
exit 3
|
|
51
|
+
fi
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
# Compilation should occur.
|
|
55
|
+
exit 0
|
package/bin/prepublish
ADDED
package/bin/remap-paths
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const FS = require('fs');
|
|
4
|
+
const Path = require('path');
|
|
5
|
+
|
|
6
|
+
const JAVASCRIPT_EXTENSION = '.js';
|
|
7
|
+
const DECLARATION_EXTENSION = '.d.ts';
|
|
8
|
+
const UTF8_ENCODING = 'utf8';
|
|
9
|
+
const DIST_PATH = Path.resolve(__dirname, '../dist');
|
|
10
|
+
|
|
11
|
+
function processDirectory(directoryPath) {
|
|
12
|
+
const children = FS.readdirSync(directoryPath);
|
|
13
|
+
|
|
14
|
+
children.forEach(function each(child) {
|
|
15
|
+
// Ignore hidden files.
|
|
16
|
+
if (child[0] === '.') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const
|
|
21
|
+
childPath = Path.resolve(directoryPath, child),
|
|
22
|
+
parsedPath = Path.parse(childPath);
|
|
23
|
+
|
|
24
|
+
if (!parsedPath.ext) {
|
|
25
|
+
processDirectory(childPath);
|
|
26
|
+
} else if (parsedPath.ext === JAVASCRIPT_EXTENSION) {
|
|
27
|
+
processSourceFile(childPath);
|
|
28
|
+
} else if (childPath.slice(-5) === DECLARATION_EXTENSION) {
|
|
29
|
+
processDeclarationFile(childPath);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function processSourceFile(filePath) {
|
|
35
|
+
const contents = FS.readFileSync(filePath, UTF8_ENCODING);
|
|
36
|
+
|
|
37
|
+
const lines = contents.split('\n').map(function map(line) {
|
|
38
|
+
return line.replace(/require\("([^"]+)/g, function replacer(match, path) {
|
|
39
|
+
if (path[0] === '.') {
|
|
40
|
+
return match;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let dependencyPath = DIST_PATH + '/src/' + path + '.js';
|
|
44
|
+
|
|
45
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
46
|
+
// Fall back to checking whether there's an index.js in a directory
|
|
47
|
+
// of this name, instead of a toplevel .js source file directly.
|
|
48
|
+
dependencyPath = DIST_PATH + '/src/' + path + '/index.js';
|
|
49
|
+
|
|
50
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
51
|
+
// Well, we tried.
|
|
52
|
+
return match;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const parsedFile = Path.parse(filePath);
|
|
57
|
+
const parsedDependency = Path.parse(dependencyPath);
|
|
58
|
+
|
|
59
|
+
let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
|
|
60
|
+
|
|
61
|
+
if (relativeDirectory === '') {
|
|
62
|
+
relativeDirectory = '.';
|
|
63
|
+
} else {
|
|
64
|
+
relativeDirectory = './' + relativeDirectory;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const relativePath = relativeDirectory + '/' + parsedDependency.base;
|
|
68
|
+
|
|
69
|
+
return 'require("' + relativePath;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function processDeclarationFile(filePath) {
|
|
77
|
+
const contents = FS.readFileSync(filePath, UTF8_ENCODING);
|
|
78
|
+
|
|
79
|
+
const lines = contents.split('\n').map(function map(line) {
|
|
80
|
+
return line.replace(/from '([^']+)/g, function replacer(match, path) {
|
|
81
|
+
if (path[0] === '.') {
|
|
82
|
+
return match;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const dependencyPath = DIST_PATH + '/src/' + path + '.d.ts';
|
|
86
|
+
|
|
87
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
88
|
+
return match;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const parsedFile = Path.parse(filePath);
|
|
92
|
+
const parsedDependency = Path.parse(dependencyPath);
|
|
93
|
+
|
|
94
|
+
let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
|
|
95
|
+
|
|
96
|
+
if (relativeDirectory === '') {
|
|
97
|
+
relativeDirectory = '.';
|
|
98
|
+
} else {
|
|
99
|
+
relativeDirectory = './' + relativeDirectory;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let relativePath = relativeDirectory + '/' + parsedDependency.base;
|
|
103
|
+
|
|
104
|
+
relativePath = relativePath.replace(DECLARATION_EXTENSION, '');
|
|
105
|
+
|
|
106
|
+
return "from '" + relativePath;
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
processDirectory('./dist', 0);
|
package/bin/test
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"noImplicitReturns": true,
|
|
5
|
+
"noImplicitAny": true,
|
|
6
|
+
"strictNullChecks": true,
|
|
7
|
+
"noUnusedLocals": true,
|
|
8
|
+
"strictPropertyInitialization": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"baseUrl": "../src",
|
|
11
|
+
"target": "es2020",
|
|
12
|
+
"module": "commonjs",
|
|
13
|
+
"outDir": "../dist",
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"jsx": "react",
|
|
17
|
+
"lib": [
|
|
18
|
+
"esnext",
|
|
19
|
+
"dom"
|
|
20
|
+
],
|
|
21
|
+
"typeRoots": [
|
|
22
|
+
"../node_modules/@types"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"include": [
|
|
26
|
+
"../src/**/*.ts",
|
|
27
|
+
"../src/**/*.tsx",
|
|
28
|
+
"../test/unit/**/*.ts",
|
|
29
|
+
"../test/unit/**/*.tsx",
|
|
30
|
+
"../test/integration/**/*.ts",
|
|
31
|
+
"../test/integration/**/*.tsx"
|
|
32
|
+
],
|
|
33
|
+
"exclude": [
|
|
34
|
+
"../node_modules",
|
|
35
|
+
"../**/dist/**/*"
|
|
36
|
+
]
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fc3/mmcadi",
|
|
3
|
+
"description": "multimedia calendar + diary",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "fc3",
|
|
6
|
+
"private": false,
|
|
7
|
+
"homepage": "https://0xfc3/software/mmcadi",
|
|
8
|
+
"repository": "https://git.sr.ht/~fc3/mmcadi",
|
|
9
|
+
"license": "GPL-3.0-or-later",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"formidable": "^3.5.2",
|
|
12
|
+
"marked": "^16.3.0",
|
|
13
|
+
"node-statsd": "0.1.1",
|
|
14
|
+
"ws": "^8.18.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/formidable": "^3.4.5",
|
|
18
|
+
"@types/node": "22.13.10",
|
|
19
|
+
"@types/node-statsd": "0.1.6",
|
|
20
|
+
"@types/ws": "^8.18.0",
|
|
21
|
+
"esbuild": "^0.25.10",
|
|
22
|
+
"typescript": "5.7.2"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"npm": ">= 10.2.0",
|
|
26
|
+
"node": ">= v20.0.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"install": "./bin/install",
|
|
30
|
+
"test": "./bin/test",
|
|
31
|
+
"prepublishOnly": "./bin/prepublish"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Server from 'server';
|
|
2
|
+
import ServerSettings from 'type/server-settings';
|
|
3
|
+
|
|
4
|
+
async function start(settings: ServerSettings): Promise<Server> {
|
|
5
|
+
const server = new Server(settings);
|
|
6
|
+
|
|
7
|
+
await server.start();
|
|
8
|
+
|
|
9
|
+
return server;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default start;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {InvariantViolation} from 'lib/errors';
|
|
2
|
+
|
|
3
|
+
import PageFactory from 'client/factory/page';
|
|
4
|
+
import Page from 'client/page';
|
|
5
|
+
import getMetaValue from 'client/utility/get-meta-value';
|
|
6
|
+
import PageType from 'client/enum/page-type';
|
|
7
|
+
|
|
8
|
+
class Client {
|
|
9
|
+
public start(): void {
|
|
10
|
+
try {
|
|
11
|
+
const page = this.buildPage();
|
|
12
|
+
|
|
13
|
+
page.start();
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (!(error instanceof Error)) {
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
document.body.innerHTML = `
|
|
20
|
+
<main>
|
|
21
|
+
<section class="red">
|
|
22
|
+
<strong>ERROR:</strong>
|
|
23
|
+
${error.message}
|
|
24
|
+
<pre>${error.stack}</pre>
|
|
25
|
+
</section>
|
|
26
|
+
</main>
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private buildPage(): Page {
|
|
32
|
+
const page_type = this.determinePageType();
|
|
33
|
+
const factory = new PageFactory(page_type);
|
|
34
|
+
const page = factory.create();
|
|
35
|
+
|
|
36
|
+
return page;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private determinePageType(): PageType {
|
|
40
|
+
const meta_value = getMetaValue('page_type');
|
|
41
|
+
const page_type = meta_value as PageType;
|
|
42
|
+
const page_types = Object.values(PageType);
|
|
43
|
+
|
|
44
|
+
if (!page_types.includes(page_type)) {
|
|
45
|
+
throw new InvariantViolation(`
|
|
46
|
+
Invalid page type: ${page_type}
|
|
47
|
+
`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return page_type;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default Client;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
enum KeyCode {
|
|
2
|
+
ENTER = 13,
|
|
3
|
+
SHIFT = 16,
|
|
4
|
+
ESCAPE = 27,
|
|
5
|
+
ONE = 49,
|
|
6
|
+
A = 65,
|
|
7
|
+
B = 66,
|
|
8
|
+
C = 67,
|
|
9
|
+
D = 68,
|
|
10
|
+
E = 69,
|
|
11
|
+
F = 70,
|
|
12
|
+
G = 71,
|
|
13
|
+
H = 72,
|
|
14
|
+
I = 73,
|
|
15
|
+
J = 74,
|
|
16
|
+
K = 75,
|
|
17
|
+
L = 76,
|
|
18
|
+
M = 77,
|
|
19
|
+
N = 78,
|
|
20
|
+
O = 79,
|
|
21
|
+
P = 80,
|
|
22
|
+
Q = 81,
|
|
23
|
+
R = 82,
|
|
24
|
+
S = 83,
|
|
25
|
+
T = 84,
|
|
26
|
+
U = 85,
|
|
27
|
+
V = 86,
|
|
28
|
+
W = 87,
|
|
29
|
+
X = 88,
|
|
30
|
+
Y = 89,
|
|
31
|
+
Z = 90
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default KeyCode;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
enum PageType {
|
|
2
|
+
HOME = 'home',
|
|
3
|
+
LOGIN = 'login',
|
|
4
|
+
LOGOUT = 'logout',
|
|
5
|
+
DAY = 'day',
|
|
6
|
+
WEEK = 'week',
|
|
7
|
+
MONTH = 'month',
|
|
8
|
+
YEAR = 'year',
|
|
9
|
+
SELECT_BLOCK_TYPE = 'select_block_type',
|
|
10
|
+
CREATE_BLOCK = 'create_block',
|
|
11
|
+
EDIT_BLOCK = 'edit_block',
|
|
12
|
+
VIEW_CUSTOM = 'view_custom',
|
|
13
|
+
EDIT_CUSTOM = 'edit_custom',
|
|
14
|
+
CONFIRM_DELETE_BLOCK = 'confirm_delete_block',
|
|
15
|
+
MOVE_BLOCK = 'move_block',
|
|
16
|
+
SETTINGS = 'settings'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default PageType;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Page from 'client/page';
|
|
2
|
+
import PageType from 'client/enum/page-type';
|
|
3
|
+
|
|
4
|
+
import HomePage from 'client/page/home';
|
|
5
|
+
import LoginPage from 'client/page/login';
|
|
6
|
+
import LogoutPage from 'client/page/logout';
|
|
7
|
+
import DayPage from 'client/page/day';
|
|
8
|
+
import MonthPage from 'client/page/month';
|
|
9
|
+
import WeekPage from 'client/page/week';
|
|
10
|
+
import YearPage from 'client/page/year';
|
|
11
|
+
import SelectBlockTypePage from 'client/page/select-block-type';
|
|
12
|
+
import CreateBlockPage from 'client/page/create-block';
|
|
13
|
+
import EditBlockPage from 'client/page/edit-block';
|
|
14
|
+
import ViewCustomPage from 'client/page/view-custom';
|
|
15
|
+
import EditCustomPage from 'client/page/edit-custom';
|
|
16
|
+
import ConfirmDeleteBlockPage from 'client/page/confirm-delete-block';
|
|
17
|
+
import MoveBlockPage from 'client/page/move-block';
|
|
18
|
+
import SettingsPage from 'client/page/settings';
|
|
19
|
+
|
|
20
|
+
interface PageConstructor {
|
|
21
|
+
new(): Page;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const PageConstructors: Record<PageType, PageConstructor> = {
|
|
25
|
+
[PageType.HOME]: HomePage,
|
|
26
|
+
[PageType.LOGIN]: LoginPage,
|
|
27
|
+
[PageType.LOGOUT]: LogoutPage,
|
|
28
|
+
[PageType.DAY]: DayPage,
|
|
29
|
+
[PageType.WEEK]: WeekPage,
|
|
30
|
+
[PageType.MONTH]: MonthPage,
|
|
31
|
+
[PageType.YEAR]: YearPage,
|
|
32
|
+
[PageType.SELECT_BLOCK_TYPE]: SelectBlockTypePage,
|
|
33
|
+
[PageType.CREATE_BLOCK]: CreateBlockPage,
|
|
34
|
+
[PageType.EDIT_BLOCK]: EditBlockPage,
|
|
35
|
+
[PageType.VIEW_CUSTOM]: ViewCustomPage,
|
|
36
|
+
[PageType.EDIT_CUSTOM]: EditCustomPage,
|
|
37
|
+
[PageType.CONFIRM_DELETE_BLOCK]: ConfirmDeleteBlockPage,
|
|
38
|
+
[PageType.MOVE_BLOCK]: MoveBlockPage,
|
|
39
|
+
[PageType.SETTINGS]: SettingsPage
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
class PageFactory {
|
|
43
|
+
private page_type: PageType;
|
|
44
|
+
|
|
45
|
+
public constructor(page_type: PageType) {
|
|
46
|
+
this.page_type = page_type;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public create(): Page {
|
|
50
|
+
const page_type = this.getPageType();
|
|
51
|
+
const page_constructor = PageConstructors[page_type];
|
|
52
|
+
|
|
53
|
+
return new page_constructor;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private getPageType(): PageType {
|
|
57
|
+
return this.page_type;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default PageFactory;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {InvariantViolation} from 'lib/errors';
|
|
2
|
+
|
|
3
|
+
import Page from 'client/page';
|
|
4
|
+
import KeyCode from 'client/enum/key-code';
|
|
5
|
+
|
|
6
|
+
class ConfirmDeleteBlockPage extends Page {
|
|
7
|
+
protected handleKey(key_code: KeyCode): void {
|
|
8
|
+
switch (key_code) {
|
|
9
|
+
case KeyCode.D:
|
|
10
|
+
return this.submitDeletionForm();
|
|
11
|
+
|
|
12
|
+
default:
|
|
13
|
+
return super.handleKey(key_code);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private submitDeletionForm(): void {
|
|
18
|
+
const element = document.getElementById('deletion-form');
|
|
19
|
+
|
|
20
|
+
if (element === null) {
|
|
21
|
+
throw new InvariantViolation('Could not find deletion form element');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const form = element as HTMLFormElement;
|
|
25
|
+
|
|
26
|
+
form.submit();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default ConfirmDeleteBlockPage;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {InvariantViolation} from 'lib/errors';
|
|
2
|
+
|
|
3
|
+
import KeyCode from 'client/enum/key-code';
|
|
4
|
+
import Page from 'client/page';
|
|
5
|
+
|
|
6
|
+
class EditBlockPage extends Page {
|
|
7
|
+
protected initEvents(): void {
|
|
8
|
+
super.initEvents();
|
|
9
|
+
|
|
10
|
+
const textarea_nodes = document.getElementsByTagName('textarea');
|
|
11
|
+
const textareas = Array.from(textarea_nodes);
|
|
12
|
+
|
|
13
|
+
textareas.forEach((textarea) => {
|
|
14
|
+
let form: HTMLFormElement | undefined;
|
|
15
|
+
let current_node: ParentNode | null = textarea;
|
|
16
|
+
|
|
17
|
+
while (current_node) {
|
|
18
|
+
current_node = current_node.parentNode;
|
|
19
|
+
|
|
20
|
+
if (current_node instanceof HTMLFormElement) {
|
|
21
|
+
form = current_node;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (form === undefined) {
|
|
27
|
+
throw new InvariantViolation(`
|
|
28
|
+
Tried to read form for textarea, but it was not set
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
textarea.addEventListener('keydown', (event: KeyboardEvent) => {
|
|
33
|
+
const key_code = event.keyCode || event.charCode;
|
|
34
|
+
|
|
35
|
+
if (key_code === KeyCode.ENTER && event.shiftKey) {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default EditBlockPage;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import KeyCode from 'client/enum/key-code';
|
|
2
|
+
import ViewCustomPage from 'client/page/view-custom';
|
|
3
|
+
|
|
4
|
+
class EditCustomPage extends ViewCustomPage {
|
|
5
|
+
protected handleKey(key_code: KeyCode): void {
|
|
6
|
+
switch (key_code) {
|
|
7
|
+
case KeyCode.U:
|
|
8
|
+
return this.toggleEditMode();
|
|
9
|
+
|
|
10
|
+
default:
|
|
11
|
+
return super.handleKey(key_code);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default EditCustomPage;
|