chrome-devtools-frontend 1.0.943709 → 1.0.945329
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/config/gni/devtools_grd_files.gni +3 -0
- package/front_end/core/common/ParsedURL.ts +1 -1
- package/front_end/core/host/UserMetrics.ts +2 -1
- package/front_end/core/i18n/i18nImpl.ts +7 -4
- package/front_end/core/i18n/locales/en-US.json +3 -72
- package/front_end/core/i18n/locales/en-XL.json +15 -84
- package/front_end/core/protocol_client/NodeURL.ts +1 -0
- package/front_end/core/sdk/CSSStyleDeclaration.ts +4 -0
- package/front_end/core/sdk/CSSStyleSheetHeader.ts +2 -3
- package/front_end/core/sdk/CompilerSourceMappingContentProvider.ts +2 -3
- package/front_end/core/sdk/Cookie.ts +17 -0
- package/front_end/core/sdk/CookieModel.ts +1 -0
- package/front_end/core/sdk/DebuggerModel.ts +5 -4
- package/front_end/core/sdk/NetworkManager.ts +4 -1
- package/front_end/core/sdk/NetworkRequest.ts +2 -2
- package/front_end/core/sdk/OverlayModel.ts +0 -9
- package/front_end/core/sdk/Resource.ts +2 -2
- package/front_end/core/sdk/Script.ts +2 -7
- package/front_end/core/sdk/sdk-meta.ts +0 -26
- package/front_end/entrypoints/inspector_main/RenderingOptions.ts +0 -13
- package/front_end/entrypoints/main/MainImpl.ts +4 -0
- package/front_end/models/bindings/BreakpointManager.ts +3 -4
- package/front_end/models/bindings/DefaultScriptMapping.ts +1 -9
- package/front_end/models/bindings/ResourceMapping.ts +1 -2
- package/front_end/models/bindings/ResourceScriptMapping.ts +3 -11
- package/front_end/models/bindings/StylesSourceMapping.ts +1 -2
- package/front_end/models/formatter/SourceFormatter.ts +0 -15
- package/front_end/models/persistence/IsolatedFileSystem.ts +7 -6
- package/front_end/models/persistence/PersistenceActions.ts +4 -1
- package/front_end/models/persistence/PlatformFileSystem.ts +3 -4
- package/front_end/models/text_utils/ContentProvider.ts +1 -2
- package/front_end/models/text_utils/StaticContentProvider.ts +2 -3
- package/front_end/models/workspace/UISourceCode.ts +2 -2
- package/front_end/models/workspace_diff/WorkspaceDiff.ts +20 -6
- package/front_end/panels/animation/animationTimeline.css +2 -0
- package/front_end/panels/application/BackForwardCacheStrings.ts +15 -75
- package/front_end/panels/application/ReportingApiView.ts +15 -1
- package/front_end/panels/application/components/EndpointsGrid.ts +63 -4
- package/front_end/panels/application/components/FrameDetailsView.ts +21 -34
- package/front_end/panels/changes/ChangesView.ts +8 -7
- package/front_end/panels/console/ConsolePinPane.ts +1 -0
- package/front_end/panels/console/ConsolePrompt.ts +121 -171
- package/front_end/panels/console/ConsoleView.ts +1 -1
- package/front_end/panels/console/consoleView.css +1 -1
- package/front_end/panels/css_overview/cssOverviewCompletedView.css +2 -2
- package/front_end/panels/elements/AccessibilityTreeUtils.ts +98 -67
- package/front_end/panels/elements/AccessibilityTreeView.ts +76 -126
- package/front_end/panels/elements/ElementsPanel.ts +6 -7
- package/front_end/panels/elements/ElementsTreeElement.ts +1 -0
- package/front_end/panels/elements/StylePropertyHighlighter.ts +29 -19
- package/front_end/panels/elements/StylesSidebarPane.ts +1 -1
- package/front_end/panels/elements/components/AccessibilityTreeNode.ts +27 -3
- package/front_end/panels/emulation/DeviceModeView.ts +3 -0
- package/front_end/panels/help/ReleaseNoteText.ts +3 -1
- package/front_end/panels/network/NetworkDataGridNode.ts +5 -1
- package/front_end/panels/snippets/ScriptSnippetFileSystem.ts +1 -1
- package/front_end/panels/sources/BreakpointEditDialog.ts +1 -0
- package/front_end/panels/sources/DebuggerPlugin.ts +1 -1
- package/front_end/panels/sources/NavigatorView.ts +1 -1
- package/front_end/panels/sources/UISourceCodeFrame.ts +0 -1
- package/front_end/panels/timeline/TimelineFlameChartDataProvider.ts +3 -34
- package/front_end/panels/timeline/TimelineUIUtils.ts +51 -3
- package/front_end/services/window_bounds/WindowBoundsService.ts +27 -0
- package/front_end/services/window_bounds/window_bounds.ts +9 -0
- package/front_end/third_party/acorn/README.chromium +2 -2
- package/front_end/third_party/acorn/acorn.ts +1 -1
- package/front_end/third_party/acorn/package/CHANGELOG.md +31 -1
- package/front_end/third_party/acorn/package/README.md +1 -1
- package/front_end/third_party/acorn/package/dist/acorn.d.ts +3 -0
- package/front_end/third_party/acorn/package/dist/acorn.js +772 -708
- package/front_end/third_party/acorn/package/dist/acorn.mjs +767 -703
- package/front_end/third_party/acorn/package/dist/bin.js +47 -21
- package/front_end/third_party/acorn/package/package.json +1 -1
- package/front_end/third_party/acorn-loose/README.chromium +2 -2
- package/front_end/third_party/acorn-loose/package/CHANGELOG.md +12 -0
- package/front_end/third_party/acorn-loose/package/dist/acorn-loose.js +27 -7
- package/front_end/third_party/acorn-loose/package/dist/acorn-loose.mjs +28 -8
- package/front_end/third_party/acorn-loose/package/package.json +2 -2
- package/front_end/third_party/codemirror.next/bundle.ts +4 -3
- package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
- package/front_end/third_party/codemirror.next/codemirror.next.d.ts +39 -1
- package/front_end/third_party/codemirror.next/codemirror.next.js +1 -1
- package/front_end/third_party/codemirror.next/package.json +4 -4
- package/front_end/third_party/i18n/i18n-impl.ts +1 -1
- package/front_end/third_party/lit-html/README.chromium +2 -2
- package/front_end/third_party/lit-html/package/CHANGELOG.md +216 -28
- package/front_end/third_party/lit-html/package/LICENSE +9 -9
- package/front_end/third_party/lit-html/package/README.md +12 -162
- package/front_end/third_party/lit-html/package/async-directive.d.ts +23 -54
- package/front_end/third_party/lit-html/package/async-directive.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/async-directive.js +2 -7
- package/front_end/third_party/lit-html/package/async-directive.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/async-directive.d.ts +23 -54
- package/front_end/third_party/lit-html/package/development/async-directive.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/async-directive.js +44 -194
- package/front_end/third_party/lit-html/package/development/async-directive.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directive-helpers.d.ts +6 -5
- package/front_end/third_party/lit-html/package/development/directive-helpers.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directive-helpers.js +25 -9
- package/front_end/third_party/lit-html/package/development/directive-helpers.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directive.d.ts +3 -16
- package/front_end/third_party/lit-html/package/development/directive.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directive.js +6 -1
- package/front_end/third_party/lit-html/package/development/directive.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/async-append.d.ts +7 -14
- package/front_end/third_party/lit-html/package/development/directives/async-append.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/async-append.js +17 -58
- package/front_end/third_party/lit-html/package/development/directives/async-append.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/async-replace.d.ts +9 -14
- package/front_end/third_party/lit-html/package/development/directives/async-replace.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/async-replace.js +57 -37
- package/front_end/third_party/lit-html/package/development/directives/async-replace.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/cache.d.ts +2 -3
- package/front_end/third_party/lit-html/package/development/directives/cache.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/cache.js +4 -6
- package/front_end/third_party/lit-html/package/development/directives/cache.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/class-map.d.ts +2 -2
- package/front_end/third_party/lit-html/package/development/directives/class-map.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/class-map.js +17 -7
- package/front_end/third_party/lit-html/package/development/directives/class-map.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/guard.d.ts +3 -2
- package/front_end/third_party/lit-html/package/development/directives/guard.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/guard.js +3 -2
- package/front_end/third_party/lit-html/package/development/directives/guard.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/live.d.ts +4 -3
- package/front_end/third_party/lit-html/package/development/directives/live.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/live.js +5 -7
- package/front_end/third_party/lit-html/package/development/directives/live.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/private-async-helpers.d.ts +58 -0
- package/front_end/third_party/lit-html/package/development/directives/private-async-helpers.d.ts.map +1 -0
- package/front_end/third_party/lit-html/package/development/directives/private-async-helpers.js +85 -0
- package/front_end/third_party/lit-html/package/development/directives/private-async-helpers.js.map +1 -0
- package/front_end/third_party/lit-html/package/development/directives/ref.d.ts +14 -11
- package/front_end/third_party/lit-html/package/development/directives/ref.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/ref.js +13 -11
- package/front_end/third_party/lit-html/package/development/directives/ref.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/repeat.d.ts +8 -4
- package/front_end/third_party/lit-html/package/development/directives/repeat.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/repeat.js +23 -9
- package/front_end/third_party/lit-html/package/development/directives/repeat.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/style-map.d.ts +1 -2
- package/front_end/third_party/lit-html/package/development/directives/style-map.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/style-map.js +1 -2
- package/front_end/third_party/lit-html/package/development/directives/style-map.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/template-content.d.ts +1 -2
- package/front_end/third_party/lit-html/package/development/directives/template-content.js +1 -2
- package/front_end/third_party/lit-html/package/development/directives/unsafe-html.d.ts +6 -4
- package/front_end/third_party/lit-html/package/development/directives/unsafe-html.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/unsafe-html.js +7 -5
- package/front_end/third_party/lit-html/package/development/directives/unsafe-html.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/unsafe-svg.d.ts +4 -1
- package/front_end/third_party/lit-html/package/development/directives/unsafe-svg.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/unsafe-svg.js +3 -0
- package/front_end/third_party/lit-html/package/development/directives/unsafe-svg.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/until.d.ts +12 -8
- package/front_end/third_party/lit-html/package/development/directives/until.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/directives/until.js +63 -23
- package/front_end/third_party/lit-html/package/development/directives/until.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/experimental-hydrate.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/experimental-hydrate.js +9 -8
- package/front_end/third_party/lit-html/package/development/experimental-hydrate.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/lit-html.d.ts +81 -136
- package/front_end/third_party/lit-html/package/development/lit-html.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/lit-html.js +249 -76
- package/front_end/third_party/lit-html/package/development/lit-html.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/polyfill-support.d.ts +1 -41
- package/front_end/third_party/lit-html/package/development/polyfill-support.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/polyfill-support.js +40 -21
- package/front_end/third_party/lit-html/package/development/polyfill-support.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/private-ssr-support.d.ts +12 -10
- package/front_end/third_party/lit-html/package/development/private-ssr-support.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/private-ssr-support.js +11 -3
- package/front_end/third_party/lit-html/package/development/private-ssr-support.js.map +1 -1
- package/front_end/third_party/lit-html/package/development/static.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/development/static.js +6 -5
- package/front_end/third_party/lit-html/package/development/static.js.map +1 -1
- package/front_end/third_party/lit-html/package/directive-helpers.d.ts +6 -5
- package/front_end/third_party/lit-html/package/directive-helpers.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directive-helpers.js +2 -2
- package/front_end/third_party/lit-html/package/directive-helpers.js.map +1 -1
- package/front_end/third_party/lit-html/package/directive.d.ts +3 -16
- package/front_end/third_party/lit-html/package/directive.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directive.js +1 -1
- package/front_end/third_party/lit-html/package/directive.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/async-append.d.ts +7 -14
- package/front_end/third_party/lit-html/package/directives/async-append.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/async-append.js +2 -6
- package/front_end/third_party/lit-html/package/directives/async-append.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/async-replace.d.ts +9 -14
- package/front_end/third_party/lit-html/package/directives/async-replace.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/async-replace.js +2 -5
- package/front_end/third_party/lit-html/package/directives/async-replace.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/cache.d.ts +2 -3
- package/front_end/third_party/lit-html/package/directives/cache.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/cache.js +2 -5
- package/front_end/third_party/lit-html/package/directives/cache.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/class-map.d.ts +2 -2
- package/front_end/third_party/lit-html/package/directives/class-map.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/class-map.js +2 -4
- package/front_end/third_party/lit-html/package/directives/class-map.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/guard.d.ts +3 -2
- package/front_end/third_party/lit-html/package/directives/guard.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/guard.js +2 -4
- package/front_end/third_party/lit-html/package/directives/guard.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/live.d.ts +4 -3
- package/front_end/third_party/lit-html/package/directives/live.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/live.js +1 -4
- package/front_end/third_party/lit-html/package/directives/live.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/private-async-helpers.d.ts +58 -0
- package/front_end/third_party/lit-html/package/directives/private-async-helpers.d.ts.map +1 -0
- package/front_end/third_party/lit-html/package/directives/private-async-helpers.js +7 -0
- package/front_end/third_party/lit-html/package/directives/private-async-helpers.js.map +1 -0
- package/front_end/third_party/lit-html/package/directives/ref.d.ts +14 -11
- package/front_end/third_party/lit-html/package/directives/ref.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/ref.js +2 -5
- package/front_end/third_party/lit-html/package/directives/ref.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/repeat.d.ts +8 -4
- package/front_end/third_party/lit-html/package/directives/repeat.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/repeat.js +2 -5
- package/front_end/third_party/lit-html/package/directives/repeat.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/style-map.d.ts +1 -2
- package/front_end/third_party/lit-html/package/directives/style-map.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/style-map.js +2 -4
- package/front_end/third_party/lit-html/package/directives/style-map.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/template-content.d.ts +1 -2
- package/front_end/third_party/lit-html/package/directives/template-content.js +2 -4
- package/front_end/third_party/lit-html/package/directives/template-content.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/unsafe-html.d.ts +6 -4
- package/front_end/third_party/lit-html/package/directives/unsafe-html.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/unsafe-html.js +2 -4
- package/front_end/third_party/lit-html/package/directives/unsafe-html.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/unsafe-svg.d.ts +4 -1
- package/front_end/third_party/lit-html/package/directives/unsafe-svg.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/unsafe-svg.js.map +1 -1
- package/front_end/third_party/lit-html/package/directives/until.d.ts +12 -8
- package/front_end/third_party/lit-html/package/directives/until.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/directives/until.js +2 -6
- package/front_end/third_party/lit-html/package/directives/until.js.map +1 -1
- package/front_end/third_party/lit-html/package/experimental-hydrate.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/experimental-hydrate.js +2 -5
- package/front_end/third_party/lit-html/package/experimental-hydrate.js.map +1 -1
- package/front_end/third_party/lit-html/package/lit-html.d.ts +81 -136
- package/front_end/third_party/lit-html/package/lit-html.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/lit-html.js +1 -1
- package/front_end/third_party/lit-html/package/lit-html.js.map +1 -1
- package/front_end/third_party/lit-html/package/package.json +75 -24
- package/front_end/third_party/lit-html/package/polyfill-support.d.ts +1 -41
- package/front_end/third_party/lit-html/package/polyfill-support.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/polyfill-support.js +1 -1
- package/front_end/third_party/lit-html/package/polyfill-support.js.map +1 -1
- package/front_end/third_party/lit-html/package/private-ssr-support.d.ts +12 -10
- package/front_end/third_party/lit-html/package/private-ssr-support.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/private-ssr-support.js +2 -2
- package/front_end/third_party/lit-html/package/private-ssr-support.js.map +1 -1
- package/front_end/third_party/lit-html/package/static.d.ts.map +1 -1
- package/front_end/third_party/lit-html/package/static.js +1 -1
- package/front_end/third_party/lit-html/package/static.js.map +1 -1
- package/front_end/third_party/marked/README.chromium +2 -2
- package/front_end/third_party/marked/marked.ts +2 -2
- package/front_end/third_party/marked/package/README.md +7 -1
- package/front_end/third_party/marked/package/bin/marked.js +214 -0
- package/front_end/third_party/marked/package/lib/marked.cjs +2907 -0
- package/front_end/third_party/marked/package/lib/marked.esm.d.ts +1 -3
- package/front_end/third_party/marked/package/lib/marked.esm.js +627 -586
- package/front_end/third_party/marked/package/lib/marked.umd.js +2913 -0
- package/front_end/third_party/marked/package/man/marked.1 +5 -24
- package/front_end/third_party/marked/package/man/marked.1.txt +21 -31
- package/front_end/third_party/marked/package/marked.min.js +1 -1
- package/front_end/third_party/marked/package/package.json +41 -32
- package/front_end/third_party/marked/package/src/Lexer.js +109 -108
- package/front_end/third_party/marked/package/src/Parser.js +38 -15
- package/front_end/third_party/marked/package/src/Renderer.js +5 -5
- package/front_end/third_party/marked/package/src/Slugger.js +2 -2
- package/front_end/third_party/marked/package/src/TextRenderer.js +2 -2
- package/front_end/third_party/marked/package/src/Tokenizer.js +215 -190
- package/front_end/third_party/marked/package/src/defaults.js +6 -9
- package/front_end/third_party/marked/package/src/helpers.js +16 -27
- package/front_end/third_party/marked/package/src/marked.js +146 -63
- package/front_end/third_party/marked/package/src/rules.js +20 -45
- package/front_end/third_party/wasmparser/README.chromium +2 -2
- package/front_end/third_party/wasmparser/package/.github/workflows/main.yml +47 -0
- package/front_end/third_party/wasmparser/package/CHANGELOG.md +12 -0
- package/front_end/third_party/wasmparser/package/dist/cjs/WasmParser.js +53 -53
- package/front_end/third_party/wasmparser/package/dist/cjs/WasmParser.js.map +1 -1
- package/front_end/third_party/wasmparser/package/dist/esm/WasmParser.js +53 -53
- package/front_end/third_party/wasmparser/package/dist/esm/WasmParser.js.map +1 -1
- package/front_end/third_party/wasmparser/package/package.json +1 -1
- package/front_end/third_party/wasmparser/package/src/WasmParser.ts +53 -53
- package/front_end/ui/components/text_editor/TextEditor.ts +29 -0
- package/front_end/ui/components/text_editor/config.ts +36 -14
- package/front_end/ui/components/text_editor/javascript.ts +14 -9
- package/front_end/ui/components/text_editor/theme.ts +29 -4
- package/front_end/ui/legacy/InspectorView.ts +1 -1
- package/front_end/ui/legacy/ViewManager.ts +6 -0
- package/front_end/ui/legacy/components/cookie_table/CookiesTable.ts +20 -0
- package/front_end/ui/legacy/components/source_frame/SourceFrame.ts +1 -0
- package/front_end/ui/legacy/components/utils/Linkifier.ts +49 -79
- package/front_end/ui/legacy/themeColors.css +2 -0
- package/inspector_overlay/main.ts +3 -0
- package/package.json +1 -1
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Copyright 2017 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
-
import { Directive, PartInfo } from '../directive.js';
|
|
7
6
|
import { ChildPart, noChange } from '../lit-html.js';
|
|
8
|
-
|
|
7
|
+
import { Directive, PartInfo } from '../directive.js';
|
|
9
8
|
export declare type KeyFn<T> = (item: T, index: number) => unknown;
|
|
10
9
|
export declare type ItemTemplate<T> = (item: T, index: number) => unknown;
|
|
11
10
|
declare class RepeatDirective extends Directive {
|
|
@@ -40,8 +39,13 @@ export interface RepeatDirectiveFn {
|
|
|
40
39
|
* The `keyFn` takes two parameters, the item and its index, and returns a unique key value.
|
|
41
40
|
*
|
|
42
41
|
* ```js
|
|
43
|
-
*
|
|
44
|
-
|
|
42
|
+
* html`
|
|
43
|
+
* <ol>
|
|
44
|
+
* ${repeat(this.items, (item) => item.id, (item, index) => {
|
|
45
|
+
* return html`<li>${index}: ${item.name}</li>`;
|
|
46
|
+
* })}
|
|
47
|
+
* </ol>
|
|
48
|
+
* `
|
|
45
49
|
* ```
|
|
46
50
|
*
|
|
47
51
|
* **Important**: If providing a `keyFn`, keys *must* be unique for all items in a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/directives/repeat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAY,SAAS,EAAE,QAAQ,EAAW,MAAM,iBAAiB,CAAC;AASzE,oBAAY,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAC3D,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAalE,cAAM,eAAgB,SAAQ,SAAS;IACrC,OAAO,CAAC,SAAS,CAAC,CAAY;gBAElB,QAAQ,EAAE,QAAQ;IAO9B,OAAO,CAAC,iBAAiB;IAyBzB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;IACxE,MAAM,CAAC,CAAC,EACN,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EACjC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,KAAK,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/directives/repeat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAY,SAAS,EAAE,QAAQ,EAAW,MAAM,iBAAiB,CAAC;AASzE,oBAAY,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAC3D,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAalE,cAAM,eAAgB,SAAQ,SAAS;IACrC,OAAO,CAAC,SAAS,CAAC,CAAY;gBAElB,QAAQ,EAAE,QAAQ;IAO9B,OAAO,CAAC,iBAAiB;IAyBzB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;IACxE,MAAM,CAAC,CAAC,EACN,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EACjC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,KAAK,CAAC,OAAO,CAAC;IASR,MAAM,CAAC,CAAC,EACf,aAAa,EAAE,SAAS,EACxB,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE;QAClC,QAAQ,CAAC,CAAC,CAAC;QACX,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;QAC1B,YAAY,CAAC,CAAC,CAAC;KAChB;CA4VJ;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,CAAC,EACA,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAC3C,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC;IACX,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAC5D,CAAC,CAAC,EACA,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EACjC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,MAAM,mBAAkD,CAAC;AAEtE;;;GAGG;AACH,YAAY,EAAC,eAAe,EAAC,CAAC"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import{getCommittedValue as l,insertPart as i,removePart as n,
|
|
2
|
-
import{directive as s,Directive as t,PartType as r}from"../directive.js";
|
|
3
|
-
import{noChange as e}from"../lit-html.js";
|
|
4
|
-
|
|
1
|
+
import{noChange as e}from"../lit-html.js";import{directive as s,Directive as t,PartType as r}from"../directive.js";import{getCommittedValue as l,setChildPartValue as o,insertPart as i,removePart as n,setCommittedValue as f}from"../directive-helpers.js";
|
|
5
2
|
/**
|
|
6
3
|
* @license
|
|
7
4
|
* Copyright 2017 Google LLC
|
|
8
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
6
|
*/
|
|
10
|
-
const u=(e,s,t)=>{const r=new Map;for(let l=s;l<=t;l++)r.set(e[l],l);return r},c=s(class extends t{constructor(e){if(super(e),e.type!==r.CHILD)throw Error("repeat() can only be used in text expressions")}
|
|
7
|
+
const u=(e,s,t)=>{const r=new Map;for(let l=s;l<=t;l++)r.set(e[l],l);return r},c=s(class extends t{constructor(e){if(super(e),e.type!==r.CHILD)throw Error("repeat() can only be used in text expressions")}dt(e,s,t){let r;void 0===t?t=s:void 0!==s&&(r=s);const l=[],o=[];let i=0;for(const s of e)l[i]=r?r(s,i):i,o[i]=t(s,i),i++;return{values:o,keys:l}}render(e,s,t){return this.dt(e,s,t).values}update(s,[t,r,c]){var d;const a=l(s),{values:p,keys:v}=this.dt(t,r,c);if(!Array.isArray(a))return this.ct=v,p;const h=null!==(d=this.ct)&&void 0!==d?d:this.ct=[],m=[];let y,x,j=0,k=a.length-1,w=0,A=p.length-1;for(;j<=k&&w<=A;)if(null===a[j])j++;else if(null===a[k])k--;else if(h[j]===v[w])m[w]=o(a[j],p[w]),j++,w++;else if(h[k]===v[A])m[A]=o(a[k],p[A]),k--,A--;else if(h[j]===v[A])m[A]=o(a[j],p[A]),i(s,m[A+1],a[j]),j++,A--;else if(h[k]===v[w])m[w]=o(a[k],p[w]),i(s,a[j],a[k]),k--,w++;else if(void 0===y&&(y=u(v,w,A),x=u(h,j,k)),y.has(h[j]))if(y.has(h[k])){const e=x.get(v[w]),t=void 0!==e?a[e]:null;if(null===t){const e=i(s,a[j]);o(e,p[w]),m[w]=e}else m[w]=o(t,p[w]),i(s,a[j],t),a[e]=null;w++}else n(a[k]),k--;else n(a[j]),j++;for(;w<=A;){const e=i(s,m[A+1]);o(e,p[w]),m[w++]=e}for(;j<=k;){const e=a[j++];null!==e&&n(e)}return this.ct=v,f(s,m),e}});export{c as repeat};
|
|
11
8
|
//# sourceMappingURL=repeat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.js","sources":["../src/directives/repeat.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {ChildPart, noChange} from '../lit-html.js';\nimport {directive, Directive, PartInfo, PartType} from '../directive.js';\nimport {\n insertPart,\n getCommittedValue,\n removePart,\n setCommittedValue,\n setChildPartValue,\n} from '../directive-helpers.js';\n\nexport type KeyFn<T> = (item: T, index: number) => unknown;\nexport type ItemTemplate<T> = (item: T, index: number) => unknown;\n\n// Helper for generating a map of array item to its index over a subset\n// of an array (used to lazily generate `newKeyToIndexMap` and\n// `oldKeyToIndexMap`)\nconst generateMap = (list: unknown[], start: number, end: number) => {\n const map = new Map<unknown, number>();\n for (let i = start; i <= end; i++) {\n map.set(list[i], i);\n }\n return map;\n};\n\nclass RepeatDirective extends Directive {\n private _itemKeys?: unknown[];\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (partInfo.type !== PartType.CHILD) {\n throw new Error('repeat() can only be used in text expressions');\n }\n }\n\n private _getValuesAndKeys<T>(\n items: Iterable<T>,\n keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,\n template?: ItemTemplate<T>\n ) {\n let keyFn: KeyFn<T> | undefined;\n if (template === undefined) {\n template = keyFnOrTemplate;\n } else if (keyFnOrTemplate !== undefined) {\n keyFn = keyFnOrTemplate as KeyFn<T>;\n }\n const keys = [];\n const values = [];\n let index = 0;\n for (const item of items) {\n keys[index] = keyFn ? keyFn(item, index) : index;\n values[index] = template!(item, index);\n index++;\n }\n return {\n values,\n keys,\n };\n }\n\n render<T>(items: Iterable<T>, template: ItemTemplate<T>): Array<unknown>;\n render<T>(\n items: Iterable<T>,\n keyFn: KeyFn<T> | ItemTemplate<T>,\n template: ItemTemplate<T>\n ): Array<unknown>;\n render<T>(\n items: Iterable<T>,\n keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,\n template?: ItemTemplate<T>\n ) {\n return this._getValuesAndKeys(items, keyFnOrTemplate, template).values;\n }\n\n update<T>(\n containerPart: ChildPart,\n [items, keyFnOrTemplate, template]: [\n Iterable<T>,\n KeyFn<T> | ItemTemplate<T>,\n ItemTemplate<T>\n ]\n ) {\n // Old part & key lists are retrieved from the last update\n // TODO: deal with directive being swapped out?\n const oldParts = getCommittedValue(\n containerPart\n ) as Array<ChildPart | null>;\n const {values: newValues, keys: newKeys} = this._getValuesAndKeys(\n items,\n keyFnOrTemplate,\n template\n );\n\n if (!oldParts) {\n this._itemKeys = newKeys;\n return newValues;\n }\n\n const oldKeys = (this._itemKeys ??= []);\n\n // New part list will be built up as we go (either reused from\n // old parts or created for new keys in this update). This is\n // saved in the above cache at the end of the update.\n const newParts: ChildPart[] = [];\n\n // Maps from key to index for current and previous update; these\n // are generated lazily only when needed as a performance\n // optimization, since they are only required for multiple\n // non-contiguous changes in the list, which are less common.\n let newKeyToIndexMap!: Map<unknown, number>;\n let oldKeyToIndexMap!: Map<unknown, number>;\n\n // Head and tail pointers to old parts and new values\n let oldHead = 0;\n let oldTail = oldParts.length - 1;\n let newHead = 0;\n let newTail = newValues.length - 1;\n\n // Overview of O(n) reconciliation algorithm (general approach\n // based on ideas found in ivi, vue, snabbdom, etc.):\n //\n // * We start with the list of old parts and new values (and\n // arrays of their respective keys), head/tail pointers into\n // each, and we build up the new list of parts by updating\n // (and when needed, moving) old parts or creating new ones.\n // The initial scenario might look like this (for brevity of\n // the diagrams, the numbers in the array reflect keys\n // associated with the old parts or new values, although keys\n // and parts/values are actually stored in parallel arrays\n // indexed using the same head/tail pointers):\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [ , , , , , , ]\n // newKeys: [0, 2, 1, 4, 3, 7, 6] <- reflects the user's new\n // item order\n // newHead ^ ^ newTail\n //\n // * Iterate old & new lists from both sides, updating,\n // swapping, or removing parts at the head/tail locations\n // until neither head nor tail can move.\n //\n // * Example below: keys at head pointers match, so update old\n // part 0 in-place (no need to move it) and record part 0 in\n // the `newParts` list. The last thing we do is advance the\n // `oldHead` and `newHead` pointers (will be reflected in the\n // next diagram).\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [0, , , , , , ] <- heads matched: update 0\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldHead\n // & newHead\n // newHead ^ ^ newTail\n //\n // * Example below: head pointers don't match, but tail\n // pointers do, so update part 6 in place (no need to move\n // it), and record part 6 in the `newParts` list. Last,\n // advance the `oldTail` and `oldHead` pointers.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [0, , , , , , 6] <- tails matched: update 6\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldTail\n // & newTail\n // newHead ^ ^ newTail\n //\n // * If neither head nor tail match; next check if one of the\n // old head/tail items was removed. We first need to generate\n // the reverse map of new keys to index (`newKeyToIndexMap`),\n // which is done once lazily as a performance optimization,\n // since we only hit this case if multiple non-contiguous\n // changes were made. Note that for contiguous removal\n // anywhere in the list, the head and tails would advance\n // from either end and pass each other before we get to this\n // case and removals would be handled in the final while loop\n // without needing to generate the map.\n //\n // * Example below: The key at `oldTail` was removed (no longer\n // in the `newKeyToIndexMap`), so remove that part from the\n // DOM and advance just the `oldTail` pointer.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [0, , , , , , 6] <- 5 not in new map: remove\n // newKeys: [0, 2, 1, 4, 3, 7, 6] 5 and advance oldTail\n // newHead ^ ^ newTail\n //\n // * Once head and tail cannot move, any mismatches are due to\n // either new or moved items; if a new key is in the previous\n // \"old key to old index\" map, move the old part to the new\n // location, otherwise create and insert a new part. Note\n // that when moving an old part we null its position in the\n // oldParts array if it lies between the head and tail so we\n // know to skip it when the pointers get there.\n //\n // * Example below: neither head nor tail match, and neither\n // were removed; so find the `newHead` key in the\n // `oldKeyToIndexMap`, and move that old part's DOM into the\n // next head position (before `oldParts[oldHead]`). Last,\n // null the part in the `oldPart` array since it was\n // somewhere in the remaining oldParts still to be scanned\n // (between the head and tail pointers) so that we know to\n // skip that old part on future iterations.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, , , , , 6] <- stuck: update & move 2\n // newKeys: [0, 2, 1, 4, 3, 7, 6] into place and advance\n // newHead\n // newHead ^ ^ newTail\n //\n // * Note that for moves/insertions like the one above, a part\n // inserted at the head pointer is inserted before the\n // current `oldParts[oldHead]`, and a part inserted at the\n // tail pointer is inserted before `newParts[newTail+1]`. The\n // seeming asymmetry lies in the fact that new parts are\n // moved into place outside in, so to the right of the head\n // pointer are old parts, and to the right of the tail\n // pointer are new parts.\n //\n // * We always restart back from the top of the algorithm,\n // allowing matching and simple updates in place to\n // continue...\n //\n // * Example below: the head pointers once again match, so\n // simply update part 1 and record it in the `newParts`\n // array. Last, advance both head pointers.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, , , , 6] <- heads matched: update 1\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldHead\n // & newHead\n // newHead ^ ^ newTail\n //\n // * As mentioned above, items that were moved as a result of\n // being stuck (the final else clause in the code below) are\n // marked with null, so we always advance old pointers over\n // these so we're comparing the next actual old value on\n // either end.\n //\n // * Example below: `oldHead` is null (already placed in\n // newParts), so advance `oldHead`.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6] <- old head already used:\n // newParts: [0, 2, 1, , , , 6] advance oldHead\n // newKeys: [0, 2, 1, 4, 3, 7, 6]\n // newHead ^ ^ newTail\n //\n // * Note it's not critical to mark old parts as null when they\n // are moved from head to tail or tail to head, since they\n // will be outside the pointer range and never visited again.\n //\n // * Example below: Here the old tail key matches the new head\n // key, so the part at the `oldTail` position and move its\n // DOM to the new head position (before `oldParts[oldHead]`).\n // Last, advance `oldTail` and `newHead` pointers.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, 4, , , 6] <- old tail matches new\n // newKeys: [0, 2, 1, 4, 3, 7, 6] head: update & move 4,\n // advance oldTail & newHead\n // newHead ^ ^ newTail\n //\n // * Example below: Old and new head keys match, so update the\n // old head part in place, and advance the `oldHead` and\n // `newHead` pointers.\n //\n // oldHead v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, 4, 3, ,6] <- heads match: update 3\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance oldHead &\n // newHead\n // newHead ^ ^ newTail\n //\n // * Once the new or old pointers move past each other then all\n // we have left is additions (if old list exhausted) or\n // removals (if new list exhausted). Those are handled in the\n // final while loops at the end.\n //\n // * Example below: `oldHead` exceeded `oldTail`, so we're done\n // with the main loop. Create the remaining part and insert\n // it at the new head position, and the update is complete.\n //\n // (oldHead > oldTail)\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, 4, 3, 7 ,6] <- create and insert 7\n // newKeys: [0, 2, 1, 4, 3, 7, 6]\n // newHead ^ newTail\n //\n // * Note that the order of the if/else clauses is not\n // important to the algorithm, as long as the null checks\n // come first (to ensure we're always working on valid old\n // parts) and that the final else clause comes last (since\n // that's where the expensive moves occur). The order of\n // remaining clauses is is just a simple guess at which cases\n // will be most common.\n //\n // * TODO(kschaaf) Note, we could calculate the longest\n // increasing subsequence (LIS) of old items in new position,\n // and only move those not in the LIS set. However that costs\n // O(nlogn) time and adds a bit more code, and only helps\n // make rare types of mutations require fewer moves. The\n // above handles removes, adds, reversal, swaps, and single\n // moves of contiguous items in linear time, in the minimum\n // number of moves. As the number of multiple moves where LIS\n // might help approaches a random shuffle, the LIS\n // optimization becomes less helpful, so it seems not worth\n // the code at this point. Could reconsider if a compelling\n // case arises.\n\n while (oldHead <= oldTail && newHead <= newTail) {\n if (oldParts[oldHead] === null) {\n // `null` means old part at head has already been used\n // below; skip\n oldHead++;\n } else if (oldParts[oldTail] === null) {\n // `null` means old part at tail has already been used\n // below; skip\n oldTail--;\n } else if (oldKeys[oldHead] === newKeys[newHead]) {\n // Old head matches new head; update in place\n newParts[newHead] = setChildPartValue(\n oldParts[oldHead]!,\n newValues[newHead]\n );\n oldHead++;\n newHead++;\n } else if (oldKeys[oldTail] === newKeys[newTail]) {\n // Old tail matches new tail; update in place\n newParts[newTail] = setChildPartValue(\n oldParts[oldTail]!,\n newValues[newTail]\n );\n oldTail--;\n newTail--;\n } else if (oldKeys[oldHead] === newKeys[newTail]) {\n // Old head matches new tail; update and move to new tail\n newParts[newTail] = setChildPartValue(\n oldParts[oldHead]!,\n newValues[newTail]\n );\n insertPart(containerPart, newParts[newTail + 1], oldParts[oldHead]!);\n oldHead++;\n newTail--;\n } else if (oldKeys[oldTail] === newKeys[newHead]) {\n // Old tail matches new head; update and move to new head\n newParts[newHead] = setChildPartValue(\n oldParts[oldTail]!,\n newValues[newHead]\n );\n insertPart(containerPart, oldParts[oldHead]!, oldParts[oldTail]!);\n oldTail--;\n newHead++;\n } else {\n if (newKeyToIndexMap === undefined) {\n // Lazily generate key-to-index maps, used for removals &\n // moves below\n newKeyToIndexMap = generateMap(newKeys, newHead, newTail);\n oldKeyToIndexMap = generateMap(oldKeys, oldHead, oldTail);\n }\n if (!newKeyToIndexMap.has(oldKeys[oldHead])) {\n // Old head is no longer in new list; remove\n removePart(oldParts[oldHead]!);\n oldHead++;\n } else if (!newKeyToIndexMap.has(oldKeys[oldTail])) {\n // Old tail is no longer in new list; remove\n removePart(oldParts[oldTail]!);\n oldTail--;\n } else {\n // Any mismatches at this point are due to additions or\n // moves; see if we have an old part we can reuse and move\n // into place\n const oldIndex = oldKeyToIndexMap.get(newKeys[newHead]);\n const oldPart = oldIndex !== undefined ? oldParts[oldIndex] : null;\n if (oldPart === null) {\n // No old part for this value; create a new one and\n // insert it\n const newPart = insertPart(containerPart, oldParts[oldHead]!);\n setChildPartValue(newPart, newValues[newHead]);\n newParts[newHead] = newPart;\n } else {\n // Reuse old part\n newParts[newHead] = setChildPartValue(oldPart, newValues[newHead]);\n insertPart(containerPart, oldParts[oldHead]!, oldPart);\n // This marks the old part as having been used, so that\n // it will be skipped in the first two checks above\n oldParts[oldIndex as number] = null;\n }\n newHead++;\n }\n }\n }\n // Add parts for any remaining new values\n while (newHead <= newTail) {\n // For all remaining additions, we insert before last new\n // tail, since old pointers are no longer valid\n const newPart = insertPart(containerPart, newParts[newTail + 1]);\n setChildPartValue(newPart, newValues[newHead]);\n newParts[newHead++] = newPart;\n }\n // Remove any remaining unused old parts\n while (oldHead <= oldTail) {\n const oldPart = oldParts[oldHead++];\n if (oldPart !== null) {\n removePart(oldPart);\n }\n }\n\n // Save order of new parts for next round\n this._itemKeys = newKeys;\n // Directly set part value, bypassing it's dirty-checking\n setCommittedValue(containerPart, newParts);\n return noChange;\n }\n}\n\nexport interface RepeatDirectiveFn {\n <T>(\n items: Iterable<T>,\n keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,\n template?: ItemTemplate<T>\n ): unknown;\n <T>(items: Iterable<T>, template: ItemTemplate<T>): unknown;\n <T>(\n items: Iterable<T>,\n keyFn: KeyFn<T> | ItemTemplate<T>,\n template: ItemTemplate<T>\n ): unknown;\n}\n\n/**\n * A directive that repeats a series of values (usually `TemplateResults`)\n * generated from an iterable, and updates those items efficiently when the\n * iterable changes based on user-provided `keys` associated with each item.\n *\n * Note that if a `keyFn` is provided, strict key-to-DOM mapping is maintained,\n * meaning previous DOM for a given key is moved into the new position if\n * needed, and DOM will never be reused with values for different keys (new DOM\n * will always be created for new keys). This is generally the most efficient\n * way to use `repeat` since it performs minimum unnecessary work for insertions\n * and removals.\n *\n * The `keyFn` takes two parameters, the item and its index, and returns a unique key value.\n *\n * ```js\n * ${repeat(this.items, (item) => item.id, (item, index) =>\n html`<li>${index}: ${item.name}</li>`)}\n * ```\n *\n * **Important**: If providing a `keyFn`, keys *must* be unique for all items in a\n * given call to `repeat`. The behavior when two or more items have the same key\n * is undefined.\n *\n * If no `keyFn` is provided, this directive will perform similar to mapping\n * items to values, and DOM will be reused against potentially different items.\n */\nexport const repeat = directive(RepeatDirective) as RepeatDirectiveFn;\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {RepeatDirective};\n"],"names":["generateMap","list","start","end","map","Map","i","set","repeat","directive","Directive","[object Object]","partInfo","super","type","PartType","CHILD","Error","items","keyFnOrTemplate","template","keyFn","undefined","keys","values","index","item","this","_getValuesAndKeys","containerPart","oldParts","getCommittedValue","newValues","newKeys","_itemKeys","oldKeys","newParts","newKeyToIndexMap","oldKeyToIndexMap","oldHead","oldTail","length","newHead","newTail","setChildPartValue","insertPart","has","oldIndex","get","oldPart","newPart","removePart","setCommittedValue","noChange"],"mappings":";;;;;;AAsBA,MAAMA,EAAc,CAACC,EAAiBC,EAAeC,KACnD,MAAMC,EAAM,IAAIC,IAChB,IAAK,IAAIC,EAAIJ,EAAOI,GAAKH,EAAKG,IAC5BF,EAAIG,IAAIN,EAAKK,GAAIA,GAEnB,OAAOF,GAsbII,EAASC,EAnbtB,cAA8BC,EAG5BC,YAAYC,GAEV,GADAC,MAAMD,GACFA,EAASE,OAASC,EAASC,MAC7B,MAAUC,MAAM,iDAIZN,GACNO,EACAC,EACAC,GAEA,IAAIC,OACaC,IAAbF,EACFA,EAAWD,OACkBG,IAApBH,IACTE,EAAQF,GAEV,MAAMI,EAAO,GACPC,EAAS,GACf,IAAIC,EAAQ,EACZ,IAAK,MAAMC,KAAQR,EACjBK,EAAKE,GAASJ,EAAQA,EAAMK,EAAMD,GAASA,EAC3CD,EAAOC,GAASL,EAAUM,EAAMD,GAChCA,IAEF,MAAO,CACLD,OAAAA,EACAD,KAAAA,GAUJZ,OACEO,EACAC,EACAC,GAEA,OAAOO,KAAKC,GAAkBV,EAAOC,EAAiBC,GAAUI,OAGlEb,OACEkB,GACCX,EAAOC,EAAiBC,UAQzB,MAAMU,EAAWC,EACfF,IAEKL,OAAQQ,EAAWT,KAAMU,GAAWN,KAAKC,GAC9CV,EACAC,EACAC,GAGF,IAAKU,EAEH,OADAH,KAAKO,GAAYD,EACVD,EAGT,MAAMG,YAAWR,KAAKO,kBAALP,KAAKO,GAAc,GAK9BE,EAAwB,GAM9B,IAAIC,EACAC,EAGAC,EAAU,EACVC,EAAUV,EAASW,OAAS,EAC5BC,EAAU,EACVC,EAAUX,EAAUS,OAAS,EAsMjC,KAAOF,GAAWC,GAAWE,GAAWC,GACtC,GAA0B,OAAtBb,EAASS,GAGXA,SACK,GAA0B,OAAtBT,EAASU,GAGlBA,SACK,GAAIL,EAAQI,KAAaN,EAAQS,GAEtCN,EAASM,GAAWE,EAClBd,EAASS,GACTP,EAAUU,IAEZH,IACAG,SACK,GAAIP,EAAQK,KAAaP,EAAQU,GAEtCP,EAASO,GAAWC,EAClBd,EAASU,GACTR,EAAUW,IAEZH,IACAG,SACK,GAAIR,EAAQI,KAAaN,EAAQU,GAEtCP,EAASO,GAAWC,EAClBd,EAASS,GACTP,EAAUW,IAEZE,EAAWhB,EAAeO,EAASO,EAAU,GAAIb,EAASS,IAC1DA,IACAI,SACK,GAAIR,EAAQK,KAAaP,EAAQS,GAEtCN,EAASM,GAAWE,EAClBd,EAASU,GACTR,EAAUU,IAEZG,EAAWhB,EAAeC,EAASS,GAAWT,EAASU,IACvDA,IACAE,SAQA,QANyBpB,IAArBe,IAGFA,EAAmBrC,EAAYiC,EAASS,EAASC,GACjDL,EAAmBtC,EAAYmC,EAASI,EAASC,IAE9CH,EAAiBS,IAAIX,EAAQI,IAI3B,GAAKF,EAAiBS,IAAIX,EAAQK,IAIlC,CAIL,MAAMO,EAAWT,EAAiBU,IAAIf,EAAQS,IACxCO,OAAuB3B,IAAbyB,EAAyBjB,EAASiB,GAAY,KAC9D,GAAgB,OAAZE,EAAkB,CAGpB,MAAMC,EAAUL,EAAWhB,EAAeC,EAASS,IACnDK,EAAkBM,EAASlB,EAAUU,IACrCN,EAASM,GAAWQ,OAGpBd,EAASM,GAAWE,EAAkBK,EAASjB,EAAUU,IACzDG,EAAWhB,EAAeC,EAASS,GAAWU,GAG9CnB,EAASiB,GAAsB,KAEjCL,SAtBAS,EAAWrB,EAASU,IACpBA,SALAW,EAAWrB,EAASS,IACpBA,IA8BN,KAAOG,GAAWC,GAAS,CAGzB,MAAMO,EAAUL,EAAWhB,EAAeO,EAASO,EAAU,IAC7DC,EAAkBM,EAASlB,EAAUU,IACrCN,EAASM,KAAaQ,EAGxB,KAAOX,GAAWC,GAAS,CACzB,MAAMS,EAAUnB,EAASS,KACT,OAAZU,GACFE,EAAWF,GAQf,OAHAtB,KAAKO,GAAYD,EAEjBmB,EAAkBvB,EAAeO,GAC1BiB"}
|
|
1
|
+
{"version":3,"file":"repeat.js","sources":["../src/directives/repeat.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {ChildPart, noChange} from '../lit-html.js';\nimport {directive, Directive, PartInfo, PartType} from '../directive.js';\nimport {\n insertPart,\n getCommittedValue,\n removePart,\n setCommittedValue,\n setChildPartValue,\n} from '../directive-helpers.js';\n\nexport type KeyFn<T> = (item: T, index: number) => unknown;\nexport type ItemTemplate<T> = (item: T, index: number) => unknown;\n\n// Helper for generating a map of array item to its index over a subset\n// of an array (used to lazily generate `newKeyToIndexMap` and\n// `oldKeyToIndexMap`)\nconst generateMap = (list: unknown[], start: number, end: number) => {\n const map = new Map<unknown, number>();\n for (let i = start; i <= end; i++) {\n map.set(list[i], i);\n }\n return map;\n};\n\nclass RepeatDirective extends Directive {\n private _itemKeys?: unknown[];\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (partInfo.type !== PartType.CHILD) {\n throw new Error('repeat() can only be used in text expressions');\n }\n }\n\n private _getValuesAndKeys<T>(\n items: Iterable<T>,\n keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,\n template?: ItemTemplate<T>\n ) {\n let keyFn: KeyFn<T> | undefined;\n if (template === undefined) {\n template = keyFnOrTemplate;\n } else if (keyFnOrTemplate !== undefined) {\n keyFn = keyFnOrTemplate as KeyFn<T>;\n }\n const keys = [];\n const values = [];\n let index = 0;\n for (const item of items) {\n keys[index] = keyFn ? keyFn(item, index) : index;\n values[index] = template!(item, index);\n index++;\n }\n return {\n values,\n keys,\n };\n }\n\n render<T>(items: Iterable<T>, template: ItemTemplate<T>): Array<unknown>;\n render<T>(\n items: Iterable<T>,\n keyFn: KeyFn<T> | ItemTemplate<T>,\n template: ItemTemplate<T>\n ): Array<unknown>;\n render<T>(\n items: Iterable<T>,\n keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,\n template?: ItemTemplate<T>\n ) {\n return this._getValuesAndKeys(items, keyFnOrTemplate, template).values;\n }\n\n override update<T>(\n containerPart: ChildPart,\n [items, keyFnOrTemplate, template]: [\n Iterable<T>,\n KeyFn<T> | ItemTemplate<T>,\n ItemTemplate<T>\n ]\n ) {\n // Old part & key lists are retrieved from the last update (which may\n // be primed by hydration)\n const oldParts = getCommittedValue(\n containerPart\n ) as Array<ChildPart | null>;\n const {values: newValues, keys: newKeys} = this._getValuesAndKeys(\n items,\n keyFnOrTemplate,\n template\n );\n\n // We check that oldParts, the committed value, is an Array as an\n // indicator that the previous value came from a repeat() call. If\n // oldParts is not an Array then this is the first render and we return\n // an array for lit-html's array handling to render, and remember the\n // keys.\n if (!Array.isArray(oldParts)) {\n this._itemKeys = newKeys;\n return newValues;\n }\n\n // In SSR hydration it's possible for oldParts to be an arrray but for us\n // to not have item keys because the update() hasn't run yet. We set the\n // keys to an empty array. This will cause all oldKey/newKey comparisons\n // to fail and execution to fall to the last nested brach below which\n // reuses the oldPart.\n const oldKeys = (this._itemKeys ??= []);\n\n // New part list will be built up as we go (either reused from\n // old parts or created for new keys in this update). This is\n // saved in the above cache at the end of the update.\n const newParts: ChildPart[] = [];\n\n // Maps from key to index for current and previous update; these\n // are generated lazily only when needed as a performance\n // optimization, since they are only required for multiple\n // non-contiguous changes in the list, which are less common.\n let newKeyToIndexMap!: Map<unknown, number>;\n let oldKeyToIndexMap!: Map<unknown, number>;\n\n // Head and tail pointers to old parts and new values\n let oldHead = 0;\n let oldTail = oldParts.length - 1;\n let newHead = 0;\n let newTail = newValues.length - 1;\n\n // Overview of O(n) reconciliation algorithm (general approach\n // based on ideas found in ivi, vue, snabbdom, etc.):\n //\n // * We start with the list of old parts and new values (and\n // arrays of their respective keys), head/tail pointers into\n // each, and we build up the new list of parts by updating\n // (and when needed, moving) old parts or creating new ones.\n // The initial scenario might look like this (for brevity of\n // the diagrams, the numbers in the array reflect keys\n // associated with the old parts or new values, although keys\n // and parts/values are actually stored in parallel arrays\n // indexed using the same head/tail pointers):\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [ , , , , , , ]\n // newKeys: [0, 2, 1, 4, 3, 7, 6] <- reflects the user's new\n // item order\n // newHead ^ ^ newTail\n //\n // * Iterate old & new lists from both sides, updating,\n // swapping, or removing parts at the head/tail locations\n // until neither head nor tail can move.\n //\n // * Example below: keys at head pointers match, so update old\n // part 0 in-place (no need to move it) and record part 0 in\n // the `newParts` list. The last thing we do is advance the\n // `oldHead` and `newHead` pointers (will be reflected in the\n // next diagram).\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [0, , , , , , ] <- heads matched: update 0\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldHead\n // & newHead\n // newHead ^ ^ newTail\n //\n // * Example below: head pointers don't match, but tail\n // pointers do, so update part 6 in place (no need to move\n // it), and record part 6 in the `newParts` list. Last,\n // advance the `oldTail` and `oldHead` pointers.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [0, , , , , , 6] <- tails matched: update 6\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldTail\n // & newTail\n // newHead ^ ^ newTail\n //\n // * If neither head nor tail match; next check if one of the\n // old head/tail items was removed. We first need to generate\n // the reverse map of new keys to index (`newKeyToIndexMap`),\n // which is done once lazily as a performance optimization,\n // since we only hit this case if multiple non-contiguous\n // changes were made. Note that for contiguous removal\n // anywhere in the list, the head and tails would advance\n // from either end and pass each other before we get to this\n // case and removals would be handled in the final while loop\n // without needing to generate the map.\n //\n // * Example below: The key at `oldTail` was removed (no longer\n // in the `newKeyToIndexMap`), so remove that part from the\n // DOM and advance just the `oldTail` pointer.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, 2, 3, 4, 5, 6]\n // newParts: [0, , , , , , 6] <- 5 not in new map: remove\n // newKeys: [0, 2, 1, 4, 3, 7, 6] 5 and advance oldTail\n // newHead ^ ^ newTail\n //\n // * Once head and tail cannot move, any mismatches are due to\n // either new or moved items; if a new key is in the previous\n // \"old key to old index\" map, move the old part to the new\n // location, otherwise create and insert a new part. Note\n // that when moving an old part we null its position in the\n // oldParts array if it lies between the head and tail so we\n // know to skip it when the pointers get there.\n //\n // * Example below: neither head nor tail match, and neither\n // were removed; so find the `newHead` key in the\n // `oldKeyToIndexMap`, and move that old part's DOM into the\n // next head position (before `oldParts[oldHead]`). Last,\n // null the part in the `oldPart` array since it was\n // somewhere in the remaining oldParts still to be scanned\n // (between the head and tail pointers) so that we know to\n // skip that old part on future iterations.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, , , , , 6] <- stuck: update & move 2\n // newKeys: [0, 2, 1, 4, 3, 7, 6] into place and advance\n // newHead\n // newHead ^ ^ newTail\n //\n // * Note that for moves/insertions like the one above, a part\n // inserted at the head pointer is inserted before the\n // current `oldParts[oldHead]`, and a part inserted at the\n // tail pointer is inserted before `newParts[newTail+1]`. The\n // seeming asymmetry lies in the fact that new parts are\n // moved into place outside in, so to the right of the head\n // pointer are old parts, and to the right of the tail\n // pointer are new parts.\n //\n // * We always restart back from the top of the algorithm,\n // allowing matching and simple updates in place to\n // continue...\n //\n // * Example below: the head pointers once again match, so\n // simply update part 1 and record it in the `newParts`\n // array. Last, advance both head pointers.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, , , , 6] <- heads matched: update 1\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldHead\n // & newHead\n // newHead ^ ^ newTail\n //\n // * As mentioned above, items that were moved as a result of\n // being stuck (the final else clause in the code below) are\n // marked with null, so we always advance old pointers over\n // these so we're comparing the next actual old value on\n // either end.\n //\n // * Example below: `oldHead` is null (already placed in\n // newParts), so advance `oldHead`.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6] <- old head already used:\n // newParts: [0, 2, 1, , , , 6] advance oldHead\n // newKeys: [0, 2, 1, 4, 3, 7, 6]\n // newHead ^ ^ newTail\n //\n // * Note it's not critical to mark old parts as null when they\n // are moved from head to tail or tail to head, since they\n // will be outside the pointer range and never visited again.\n //\n // * Example below: Here the old tail key matches the new head\n // key, so the part at the `oldTail` position and move its\n // DOM to the new head position (before `oldParts[oldHead]`).\n // Last, advance `oldTail` and `newHead` pointers.\n //\n // oldHead v v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, 4, , , 6] <- old tail matches new\n // newKeys: [0, 2, 1, 4, 3, 7, 6] head: update & move 4,\n // advance oldTail & newHead\n // newHead ^ ^ newTail\n //\n // * Example below: Old and new head keys match, so update the\n // old head part in place, and advance the `oldHead` and\n // `newHead` pointers.\n //\n // oldHead v oldTail\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, 4, 3, ,6] <- heads match: update 3\n // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance oldHead &\n // newHead\n // newHead ^ ^ newTail\n //\n // * Once the new or old pointers move past each other then all\n // we have left is additions (if old list exhausted) or\n // removals (if new list exhausted). Those are handled in the\n // final while loops at the end.\n //\n // * Example below: `oldHead` exceeded `oldTail`, so we're done\n // with the main loop. Create the remaining part and insert\n // it at the new head position, and the update is complete.\n //\n // (oldHead > oldTail)\n // oldKeys: [0, 1, -, 3, 4, 5, 6]\n // newParts: [0, 2, 1, 4, 3, 7 ,6] <- create and insert 7\n // newKeys: [0, 2, 1, 4, 3, 7, 6]\n // newHead ^ newTail\n //\n // * Note that the order of the if/else clauses is not\n // important to the algorithm, as long as the null checks\n // come first (to ensure we're always working on valid old\n // parts) and that the final else clause comes last (since\n // that's where the expensive moves occur). The order of\n // remaining clauses is is just a simple guess at which cases\n // will be most common.\n //\n // * Note, we could calculate the longest\n // increasing subsequence (LIS) of old items in new position,\n // and only move those not in the LIS set. However that costs\n // O(nlogn) time and adds a bit more code, and only helps\n // make rare types of mutations require fewer moves. The\n // above handles removes, adds, reversal, swaps, and single\n // moves of contiguous items in linear time, in the minimum\n // number of moves. As the number of multiple moves where LIS\n // might help approaches a random shuffle, the LIS\n // optimization becomes less helpful, so it seems not worth\n // the code at this point. Could reconsider if a compelling\n // case arises.\n\n while (oldHead <= oldTail && newHead <= newTail) {\n if (oldParts[oldHead] === null) {\n // `null` means old part at head has already been used\n // below; skip\n oldHead++;\n } else if (oldParts[oldTail] === null) {\n // `null` means old part at tail has already been used\n // below; skip\n oldTail--;\n } else if (oldKeys[oldHead] === newKeys[newHead]) {\n // Old head matches new head; update in place\n newParts[newHead] = setChildPartValue(\n oldParts[oldHead]!,\n newValues[newHead]\n );\n oldHead++;\n newHead++;\n } else if (oldKeys[oldTail] === newKeys[newTail]) {\n // Old tail matches new tail; update in place\n newParts[newTail] = setChildPartValue(\n oldParts[oldTail]!,\n newValues[newTail]\n );\n oldTail--;\n newTail--;\n } else if (oldKeys[oldHead] === newKeys[newTail]) {\n // Old head matches new tail; update and move to new tail\n newParts[newTail] = setChildPartValue(\n oldParts[oldHead]!,\n newValues[newTail]\n );\n insertPart(containerPart, newParts[newTail + 1], oldParts[oldHead]!);\n oldHead++;\n newTail--;\n } else if (oldKeys[oldTail] === newKeys[newHead]) {\n // Old tail matches new head; update and move to new head\n newParts[newHead] = setChildPartValue(\n oldParts[oldTail]!,\n newValues[newHead]\n );\n insertPart(containerPart, oldParts[oldHead]!, oldParts[oldTail]!);\n oldTail--;\n newHead++;\n } else {\n if (newKeyToIndexMap === undefined) {\n // Lazily generate key-to-index maps, used for removals &\n // moves below\n newKeyToIndexMap = generateMap(newKeys, newHead, newTail);\n oldKeyToIndexMap = generateMap(oldKeys, oldHead, oldTail);\n }\n if (!newKeyToIndexMap.has(oldKeys[oldHead])) {\n // Old head is no longer in new list; remove\n removePart(oldParts[oldHead]!);\n oldHead++;\n } else if (!newKeyToIndexMap.has(oldKeys[oldTail])) {\n // Old tail is no longer in new list; remove\n removePart(oldParts[oldTail]!);\n oldTail--;\n } else {\n // Any mismatches at this point are due to additions or\n // moves; see if we have an old part we can reuse and move\n // into place\n const oldIndex = oldKeyToIndexMap.get(newKeys[newHead]);\n const oldPart = oldIndex !== undefined ? oldParts[oldIndex] : null;\n if (oldPart === null) {\n // No old part for this value; create a new one and\n // insert it\n const newPart = insertPart(containerPart, oldParts[oldHead]!);\n setChildPartValue(newPart, newValues[newHead]);\n newParts[newHead] = newPart;\n } else {\n // Reuse old part\n newParts[newHead] = setChildPartValue(oldPart, newValues[newHead]);\n insertPart(containerPart, oldParts[oldHead]!, oldPart);\n // This marks the old part as having been used, so that\n // it will be skipped in the first two checks above\n oldParts[oldIndex as number] = null;\n }\n newHead++;\n }\n }\n }\n // Add parts for any remaining new values\n while (newHead <= newTail) {\n // For all remaining additions, we insert before last new\n // tail, since old pointers are no longer valid\n const newPart = insertPart(containerPart, newParts[newTail + 1]);\n setChildPartValue(newPart, newValues[newHead]);\n newParts[newHead++] = newPart;\n }\n // Remove any remaining unused old parts\n while (oldHead <= oldTail) {\n const oldPart = oldParts[oldHead++];\n if (oldPart !== null) {\n removePart(oldPart);\n }\n }\n\n // Save order of new parts for next round\n this._itemKeys = newKeys;\n // Directly set part value, bypassing it's dirty-checking\n setCommittedValue(containerPart, newParts);\n return noChange;\n }\n}\n\nexport interface RepeatDirectiveFn {\n <T>(\n items: Iterable<T>,\n keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,\n template?: ItemTemplate<T>\n ): unknown;\n <T>(items: Iterable<T>, template: ItemTemplate<T>): unknown;\n <T>(\n items: Iterable<T>,\n keyFn: KeyFn<T> | ItemTemplate<T>,\n template: ItemTemplate<T>\n ): unknown;\n}\n\n/**\n * A directive that repeats a series of values (usually `TemplateResults`)\n * generated from an iterable, and updates those items efficiently when the\n * iterable changes based on user-provided `keys` associated with each item.\n *\n * Note that if a `keyFn` is provided, strict key-to-DOM mapping is maintained,\n * meaning previous DOM for a given key is moved into the new position if\n * needed, and DOM will never be reused with values for different keys (new DOM\n * will always be created for new keys). This is generally the most efficient\n * way to use `repeat` since it performs minimum unnecessary work for insertions\n * and removals.\n *\n * The `keyFn` takes two parameters, the item and its index, and returns a unique key value.\n *\n * ```js\n * html`\n * <ol>\n * ${repeat(this.items, (item) => item.id, (item, index) => {\n * return html`<li>${index}: ${item.name}</li>`;\n * })}\n * </ol>\n * `\n * ```\n *\n * **Important**: If providing a `keyFn`, keys *must* be unique for all items in a\n * given call to `repeat`. The behavior when two or more items have the same key\n * is undefined.\n *\n * If no `keyFn` is provided, this directive will perform similar to mapping\n * items to values, and DOM will be reused against potentially different items.\n */\nexport const repeat = directive(RepeatDirective) as RepeatDirectiveFn;\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {RepeatDirective};\n"],"names":["generateMap","list","start","end","map","Map","i","set","repeat","directive","Directive","constructor","partInfo","super","type","PartType","CHILD","Error","_getValuesAndKeys","items","keyFnOrTemplate","template","keyFn","undefined","keys","values","index","item","render","this","update","containerPart","oldParts","getCommittedValue","newValues","newKeys","Array","isArray","_itemKeys","oldKeys","newParts","newKeyToIndexMap","oldKeyToIndexMap","oldHead","oldTail","length","newHead","newTail","setChildPartValue","insertPart","has","oldIndex","get","oldPart","newPart","removePart","setCommittedValue","noChange"],"mappings":";;;;;;AAsBA,MAAMA,EAAc,CAACC,EAAiBC,EAAeC,KACnD,MAAMC,EAAM,IAAIC,IAChB,IAAK,IAAIC,EAAIJ,EAAOI,GAAKH,EAAKG,IAC5BF,EAAIG,IAAIN,EAAKK,GAAIA,GAEnB,OAAOF,GAqcII,EAASC,EAlctB,cAA8BC,EAG5BC,YAAYC,GAEV,GADAC,MAAMD,GACFA,EAASE,OAASC,EAASC,MAC7B,MAAUC,MAAM,iDAIZC,GACNC,EACAC,EACAC,GAEA,IAAIC,OACaC,IAAbF,EACFA,EAAWD,OACkBG,IAApBH,IACTE,EAAQF,GAEV,MAAMI,EAAO,GACPC,EAAS,GACf,IAAIC,EAAQ,EACZ,IAAK,MAAMC,KAAQR,EACjBK,EAAKE,GAASJ,EAAQA,EAAMK,EAAMD,GAASA,EAC3CD,EAAOC,GAASL,EAAUM,EAAMD,GAChCA,IAEF,MAAO,CACLD,OAAAA,EACAD,KAAAA,GAUJI,OACET,EACAC,EACAC,GAEA,OAAOQ,KAAKX,GAAkBC,EAAOC,EAAiBC,GAAUI,OAGzDK,OACPC,GACCZ,EAAOC,EAAiBC,UAQzB,MAAMW,EAAWC,EACfF,IAEKN,OAAQS,EAAWV,KAAMW,GAAWN,KAAKX,GAC9CC,EACAC,EACAC,GAQF,IAAKe,MAAMC,QAAQL,GAEjB,OADAH,KAAKS,GAAYH,EACVD,EAQT,MAAMK,YAAWV,KAAKS,kBAALT,KAAKS,GAAc,GAK9BE,EAAwB,GAM9B,IAAIC,EACAC,EAGAC,EAAU,EACVC,EAAUZ,EAASa,OAAS,EAC5BC,EAAU,EACVC,EAAUb,EAAUW,OAAS,EAsMjC,KAAOF,GAAWC,GAAWE,GAAWC,GACtC,GAA0B,OAAtBf,EAASW,GAGXA,SACK,GAA0B,OAAtBX,EAASY,GAGlBA,SACK,GAAIL,EAAQI,KAAaR,EAAQW,GAEtCN,EAASM,GAAWE,EAClBhB,EAASW,GACTT,EAAUY,IAEZH,IACAG,SACK,GAAIP,EAAQK,KAAaT,EAAQY,GAEtCP,EAASO,GAAWC,EAClBhB,EAASY,GACTV,EAAUa,IAEZH,IACAG,SACK,GAAIR,EAAQI,KAAaR,EAAQY,GAEtCP,EAASO,GAAWC,EAClBhB,EAASW,GACTT,EAAUa,IAEZE,EAAWlB,EAAeS,EAASO,EAAU,GAAIf,EAASW,IAC1DA,IACAI,SACK,GAAIR,EAAQK,KAAaT,EAAQW,GAEtCN,EAASM,GAAWE,EAClBhB,EAASY,GACTV,EAAUY,IAEZG,EAAWlB,EAAeC,EAASW,GAAWX,EAASY,IACvDA,IACAE,SAQA,QANyBvB,IAArBkB,IAGFA,EAAmBzC,EAAYmC,EAASW,EAASC,GACjDL,EAAmB1C,EAAYuC,EAASI,EAASC,IAE9CH,EAAiBS,IAAIX,EAAQI,IAI3B,GAAKF,EAAiBS,IAAIX,EAAQK,IAIlC,CAIL,MAAMO,EAAWT,EAAiBU,IAAIjB,EAAQW,IACxCO,OAAuB9B,IAAb4B,EAAyBnB,EAASmB,GAAY,KAC9D,GAAgB,OAAZE,EAAkB,CAGpB,MAAMC,EAAUL,EAAWlB,EAAeC,EAASW,IACnDK,EAAkBM,EAASpB,EAAUY,IACrCN,EAASM,GAAWQ,OAGpBd,EAASM,GAAWE,EAAkBK,EAASnB,EAAUY,IACzDG,EAAWlB,EAAeC,EAASW,GAAWU,GAG9CrB,EAASmB,GAAsB,KAEjCL,SAtBAS,EAAWvB,EAASY,IACpBA,SALAW,EAAWvB,EAASW,IACpBA,IA8BN,KAAOG,GAAWC,GAAS,CAGzB,MAAMO,EAAUL,EAAWlB,EAAeS,EAASO,EAAU,IAC7DC,EAAkBM,EAASpB,EAAUY,IACrCN,EAASM,KAAaQ,EAGxB,KAAOX,GAAWC,GAAS,CACzB,MAAMS,EAAUrB,EAASW,KACT,OAAZU,GACFE,EAAWF,GAQf,OAHAxB,KAAKS,GAAYH,EAEjBqB,EAAkBzB,EAAeS,GAC1BiB"}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Copyright 2018 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
-
import { Directive, DirectiveParameters, PartInfo } from '../directive.js';
|
|
7
6
|
import { AttributePart, noChange } from '../lit-html.js';
|
|
8
|
-
|
|
7
|
+
import { Directive, DirectiveParameters, PartInfo } from '../directive.js';
|
|
9
8
|
/**
|
|
10
9
|
* A key-value set of CSS properties and values.
|
|
11
10
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-map.d.ts","sourceRoot":"","sources":["../../src/directives/style-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAEL,SAAS,EACT,mBAAmB,EACnB,QAAQ,EAET,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACpD;AAED,cAAM,iBAAkB,SAAQ,SAAS;IACvC,wBAAwB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBAE3B,QAAQ,EAAE,QAAQ;IAc9B,MAAM,CAAC,SAAS,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"style-map.d.ts","sourceRoot":"","sources":["../../src/directives/style-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAEL,SAAS,EACT,mBAAmB,EACnB,QAAQ,EAET,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACpD;AAED,cAAM,iBAAkB,SAAQ,SAAS;IACvC,wBAAwB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBAE3B,QAAQ,EAAE,QAAQ;IAc9B,MAAM,CAAC,SAAS,EAAE,SAAS;IAoBlB,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC,IAAI,CAAC;CA4C5E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,+FAA+B,CAAC;AAErD;;;GAGG;AACH,YAAY,EAAC,iBAAiB,EAAC,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import{directive as e,Directive as r,PartType as s}from"../directive.js";
|
|
2
|
-
import{noChange as t}from"../lit-html.js";
|
|
3
|
-
|
|
1
|
+
import{noChange as t}from"../lit-html.js";import{directive as e,Directive as r,PartType as s}from"../directive.js";
|
|
4
2
|
/**
|
|
5
3
|
* @license
|
|
6
4
|
* Copyright 2018 Google LLC
|
|
7
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
8
|
-
*/const i=e(class extends r{constructor(t){var e;if(super(t),t.type!==s.ATTRIBUTE||"style"!==t.name||(null===(e=t.strings)||void 0===e?void 0:e.length)>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(t){return Object.keys(t).reduce(((e,r)=>{const s=t[r];return null==s?e:e+`${r=r.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${s};`}),"")}update(e,[r]){const{style:s}=e.element;if(void 0===this.
|
|
6
|
+
*/const i=e(class extends r{constructor(t){var e;if(super(t),t.type!==s.ATTRIBUTE||"style"!==t.name||(null===(e=t.strings)||void 0===e?void 0:e.length)>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(t){return Object.keys(t).reduce(((e,r)=>{const s=t[r];return null==s?e:e+`${r=r.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${s};`}),"")}update(e,[r]){const{style:s}=e.element;if(void 0===this.ut){this.ut=new Set;for(const t in r)this.ut.add(t);return this.render(r)}this.ut.forEach((t=>{null==r[t]&&(this.ut.delete(t),t.includes("-")?s.removeProperty(t):s[t]="")}));for(const t in r){const e=r[t];null!=e&&(this.ut.add(t),t.includes("-")?s.setProperty(t,e):s[t]=e)}return t}});export{i as styleMap};
|
|
9
7
|
//# sourceMappingURL=style-map.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-map.js","sources":["../src/directives/style-map.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2018 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {AttributePart, noChange} from '../lit-html.js';\nimport {\n directive,\n Directive,\n DirectiveParameters,\n PartInfo,\n PartType,\n} from '../directive.js';\n\n/**\n * A key-value set of CSS properties and values.\n *\n * The key should be either a valid CSS property name string, like\n * `'background-color'`, or a valid JavaScript camel case property name\n * for CSSStyleDeclaration like `backgroundColor`.\n */\nexport interface StyleInfo {\n readonly [name: string]: string | undefined | null;\n}\n\nclass StyleMapDirective extends Directive {\n _previousStyleProperties?: Set<string>;\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (\n partInfo.type !== PartType.ATTRIBUTE ||\n partInfo.name !== 'style' ||\n (partInfo.strings?.length as number) > 2\n ) {\n throw new Error(\n 'The `styleMap` directive must be used in the `style` attribute ' +\n 'and must be the only part in the attribute.'\n );\n }\n }\n\n render(styleInfo: StyleInfo) {\n return Object.keys(styleInfo).reduce((style, prop) => {\n const value = styleInfo[prop];\n if (value == null) {\n return style;\n }\n // Convert property names from camel-case to dash-case, i.e.:\n // `backgroundColor` -> `background-color`\n // Vendor-prefixed names need an extra `-` appended to front:\n // `webkitAppearance` -> `-webkit-appearance`\n // Exception is any property name containing a dash, including\n // custom properties; we assume these are already dash-cased i.e.:\n // `--my-button-color` --> `--my-button-color`\n prop = prop\n .replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g, '-$&')\n .toLowerCase();\n return style + `${prop}:${value};`;\n }, '');\n }\n\n update(part: AttributePart, [styleInfo]: DirectiveParameters<this>) {\n const {style} = part.element as HTMLElement;\n\n if (this._previousStyleProperties === undefined) {\n this._previousStyleProperties = new Set();\n for (const name in styleInfo) {\n this._previousStyleProperties.add(name);\n }\n return this.render(styleInfo);\n }\n\n // Remove old properties that no longer exist in styleInfo\n // We use forEach() instead of for-of so that re don't require down-level\n // iteration.\n this._previousStyleProperties!.forEach((name) => {\n // If the name isn't in styleInfo or it's null/undefined\n if (styleInfo[name] == null) {\n this._previousStyleProperties!.delete(name);\n if (name.includes('-')) {\n style.removeProperty(name);\n } else {\n // Note reset using empty string (vs null) as IE11 does not always\n // reset via null (https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style#setting_styles)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (style as any)[name] = '';\n }\n }\n });\n\n // Add or update properties\n for (const name in styleInfo) {\n const value = styleInfo[name];\n if (value != null) {\n this._previousStyleProperties.add(name);\n if (name.includes('-')) {\n style.setProperty(name, value);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (style as any)[name] = value;\n }\n }\n }\n return noChange;\n }\n}\n\n/**\n * A directive that applies CSS properties to an element.\n *\n * `styleMap` can only be used in the `style` attribute and must be the only\n * expression in the attribute. It takes the property names in the `styleInfo`\n * object and adds the property values as CSS properties. Property names with\n * dashes (`-`) are assumed to be valid CSS property names and set on the\n * element's style object using `setProperty()`. Names without dashes are\n * assumed to be camelCased JavaScript property names and set on the element's\n * style object using property assignment, allowing the style object to\n * translate JavaScript-style names to CSS property names.\n *\n * For example `styleMap({backgroundColor: 'red', 'border-top': '5px', '--size':\n * '0'})` sets the `background-color`, `border-top` and `--size` properties.\n *\n * @param styleInfo\n */\nexport const styleMap = directive(StyleMapDirective);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {StyleMapDirective};\n"],"names":["styleMap","directive","Directive","
|
|
1
|
+
{"version":3,"file":"style-map.js","sources":["../src/directives/style-map.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2018 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {AttributePart, noChange} from '../lit-html.js';\nimport {\n directive,\n Directive,\n DirectiveParameters,\n PartInfo,\n PartType,\n} from '../directive.js';\n\n/**\n * A key-value set of CSS properties and values.\n *\n * The key should be either a valid CSS property name string, like\n * `'background-color'`, or a valid JavaScript camel case property name\n * for CSSStyleDeclaration like `backgroundColor`.\n */\nexport interface StyleInfo {\n readonly [name: string]: string | undefined | null;\n}\n\nclass StyleMapDirective extends Directive {\n _previousStyleProperties?: Set<string>;\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (\n partInfo.type !== PartType.ATTRIBUTE ||\n partInfo.name !== 'style' ||\n (partInfo.strings?.length as number) > 2\n ) {\n throw new Error(\n 'The `styleMap` directive must be used in the `style` attribute ' +\n 'and must be the only part in the attribute.'\n );\n }\n }\n\n render(styleInfo: StyleInfo) {\n return Object.keys(styleInfo).reduce((style, prop) => {\n const value = styleInfo[prop];\n if (value == null) {\n return style;\n }\n // Convert property names from camel-case to dash-case, i.e.:\n // `backgroundColor` -> `background-color`\n // Vendor-prefixed names need an extra `-` appended to front:\n // `webkitAppearance` -> `-webkit-appearance`\n // Exception is any property name containing a dash, including\n // custom properties; we assume these are already dash-cased i.e.:\n // `--my-button-color` --> `--my-button-color`\n prop = prop\n .replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g, '-$&')\n .toLowerCase();\n return style + `${prop}:${value};`;\n }, '');\n }\n\n override update(part: AttributePart, [styleInfo]: DirectiveParameters<this>) {\n const {style} = part.element as HTMLElement;\n\n if (this._previousStyleProperties === undefined) {\n this._previousStyleProperties = new Set();\n for (const name in styleInfo) {\n this._previousStyleProperties.add(name);\n }\n return this.render(styleInfo);\n }\n\n // Remove old properties that no longer exist in styleInfo\n // We use forEach() instead of for-of so that re don't require down-level\n // iteration.\n this._previousStyleProperties!.forEach((name) => {\n // If the name isn't in styleInfo or it's null/undefined\n if (styleInfo[name] == null) {\n this._previousStyleProperties!.delete(name);\n if (name.includes('-')) {\n style.removeProperty(name);\n } else {\n // Note reset using empty string (vs null) as IE11 does not always\n // reset via null (https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style#setting_styles)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (style as any)[name] = '';\n }\n }\n });\n\n // Add or update properties\n for (const name in styleInfo) {\n const value = styleInfo[name];\n if (value != null) {\n this._previousStyleProperties.add(name);\n if (name.includes('-')) {\n style.setProperty(name, value);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (style as any)[name] = value;\n }\n }\n }\n return noChange;\n }\n}\n\n/**\n * A directive that applies CSS properties to an element.\n *\n * `styleMap` can only be used in the `style` attribute and must be the only\n * expression in the attribute. It takes the property names in the `styleInfo`\n * object and adds the property values as CSS properties. Property names with\n * dashes (`-`) are assumed to be valid CSS property names and set on the\n * element's style object using `setProperty()`. Names without dashes are\n * assumed to be camelCased JavaScript property names and set on the element's\n * style object using property assignment, allowing the style object to\n * translate JavaScript-style names to CSS property names.\n *\n * For example `styleMap({backgroundColor: 'red', 'border-top': '5px', '--size':\n * '0'})` sets the `background-color`, `border-top` and `--size` properties.\n *\n * @param styleInfo\n */\nexport const styleMap = directive(StyleMapDirective);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {StyleMapDirective};\n"],"names":["styleMap","directive","Directive","constructor","partInfo","super","type","PartType","ATTRIBUTE","name","strings","length","Error","render","styleInfo","Object","keys","reduce","style","prop","value","replace","toLowerCase","update","part","element","undefined","this","_previousStyleProperties","Set","add","forEach","delete","includes","removeProperty","setProperty","noChange"],"mappings":";;;;;SA8HaA,EAAWC,EApGxB,cAAgCC,EAG9BC,YAAYC,SAEV,GADAC,MAAMD,GAEJA,EAASE,OAASC,EAASC,WACT,UAAlBJ,EAASK,iBACRL,EAASM,8BAASC,QAAoB,EAEvC,MAAUC,MACR,8GAMNC,OAAOC,GACL,OAAOC,OAAOC,KAAKF,GAAWG,QAAO,CAACC,EAAOC,KAC3C,MAAMC,EAAQN,EAAUK,GACxB,OAAa,MAATC,EACKF,EAYFA,EAAQ,GAHfC,EAAOA,EACJE,QAAQ,oCAAqC,OAC7CC,iBACuBF,OACzB,IAGIG,OAAOC,GAAsBV,IACpC,MAAMI,MAACA,GAASM,EAAKC,QAErB,QAAsCC,IAAlCC,KAAKC,GAAwC,CAC/CD,KAAKC,GAA2B,IAAIC,IACpC,IAAK,MAAMpB,KAAQK,EACjBa,KAAKC,GAAyBE,IAAIrB,GAEpC,OAAOkB,KAAKd,OAAOC,GAMrBa,KAAKC,GAA0BG,SAAStB,IAEf,MAAnBK,EAAUL,KACZkB,KAAKC,GAA0BI,OAAOvB,GAClCA,EAAKwB,SAAS,KAChBf,EAAMgB,eAAezB,GAKpBS,EAAcT,GAAQ,OAM7B,IAAK,MAAMA,KAAQK,EAAW,CAC5B,MAAMM,EAAQN,EAAUL,GACX,MAATW,IACFO,KAAKC,GAAyBE,IAAIrB,GAC9BA,EAAKwB,SAAS,KAChBf,EAAMiB,YAAY1B,EAAMW,GAGvBF,EAAcT,GAAQW,GAI7B,OAAOgB"}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Copyright 2020 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
-
import { Directive, PartInfo } from '../directive.js';
|
|
7
6
|
import { noChange } from '../lit-html.js';
|
|
8
|
-
|
|
7
|
+
import { Directive, PartInfo } from '../directive.js';
|
|
9
8
|
declare class TemplateContentDirective extends Directive {
|
|
10
9
|
private _previousTemplate?;
|
|
11
10
|
constructor(partInfo: PartInfo);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import{directive as r,Directive as e,PartType as n}from"../directive.js";
|
|
2
|
-
import{noChange as t}from"../lit-html.js";
|
|
3
|
-
|
|
1
|
+
import{noChange as t}from"../lit-html.js";import{directive as r,Directive as e,PartType as n}from"../directive.js";
|
|
4
2
|
/**
|
|
5
3
|
* @license
|
|
6
4
|
* Copyright 2020 Google LLC
|
|
7
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
8
|
-
*/const o=r(class extends e{constructor(t){if(super(t),t.type!==n.CHILD)throw Error("templateContent can only be used in child bindings")}render(r){return this.
|
|
6
|
+
*/const o=r(class extends e{constructor(t){if(super(t),t.type!==n.CHILD)throw Error("templateContent can only be used in child bindings")}render(r){return this.at===r?t:(this.at=r,document.importNode(r.content,!0))}});export{o as templateContent};
|
|
9
7
|
//# sourceMappingURL=template-content.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-content.js","sources":["../src/directives/template-content.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2020 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {noChange} from '../lit-html.js';\nimport {directive, Directive, PartInfo, PartType} from '../directive.js';\n\nclass TemplateContentDirective extends Directive {\n private _previousTemplate?: HTMLTemplateElement;\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (partInfo.type !== PartType.CHILD) {\n throw new Error('templateContent can only be used in child bindings');\n }\n }\n\n render(template: HTMLTemplateElement) {\n if (this._previousTemplate === template) {\n return noChange;\n }\n this._previousTemplate = template;\n return document.importNode(template.content, true);\n }\n}\n\n/**\n * Renders the content of a template element as HTML.\n *\n * Note, the template should be developer controlled and not user controlled.\n * Rendering a user-controlled template with this directive\n * could lead to cross-site-scripting vulnerabilities.\n */\nexport const templateContent = directive(TemplateContentDirective);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {TemplateContentDirective};\n"],"names":["templateContent","directive","Directive","
|
|
1
|
+
{"version":3,"file":"template-content.js","sources":["../src/directives/template-content.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2020 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {noChange} from '../lit-html.js';\nimport {directive, Directive, PartInfo, PartType} from '../directive.js';\n\nclass TemplateContentDirective extends Directive {\n private _previousTemplate?: HTMLTemplateElement;\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (partInfo.type !== PartType.CHILD) {\n throw new Error('templateContent can only be used in child bindings');\n }\n }\n\n render(template: HTMLTemplateElement) {\n if (this._previousTemplate === template) {\n return noChange;\n }\n this._previousTemplate = template;\n return document.importNode(template.content, true);\n }\n}\n\n/**\n * Renders the content of a template element as HTML.\n *\n * Note, the template should be developer controlled and not user controlled.\n * Rendering a user-controlled template with this directive\n * could lead to cross-site-scripting vulnerabilities.\n */\nexport const templateContent = directive(TemplateContentDirective);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {TemplateContentDirective};\n"],"names":["templateContent","directive","Directive","constructor","partInfo","super","type","PartType","CHILD","Error","render","template","this","_previousTemplate","noChange","document","importNode","content"],"mappings":";;;;;SAmCaA,EAAkBC,EA1B/B,cAAuCC,EAGrCC,YAAYC,GAEV,GADAC,MAAMD,GACFA,EAASE,OAASC,EAASC,MAC7B,MAAUC,MAAM,sDAIpBC,OAAOC,GACL,OAAIC,KAAKC,KAAsBF,EACtBG,GAETF,KAAKC,GAAoBF,EAClBI,SAASC,WAAWL,EAASM,SAAS"}
|
|
@@ -3,23 +3,25 @@
|
|
|
3
3
|
* Copyright 2017 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
+
import { nothing, TemplateResult, noChange } from '../lit-html.js';
|
|
6
7
|
import { Directive, PartInfo } from '../directive.js';
|
|
7
|
-
import { noChange , nothing, TemplateResult} from '../lit-html.js';
|
|
8
|
-
|
|
9
8
|
export declare class UnsafeHTMLDirective extends Directive {
|
|
10
9
|
static directiveName: string;
|
|
11
10
|
static resultType: number;
|
|
12
11
|
private _value;
|
|
13
12
|
private _templateResult?;
|
|
14
13
|
constructor(partInfo: PartInfo);
|
|
15
|
-
render(value: string | typeof nothing | typeof noChange): typeof noChange | typeof nothing | TemplateResult<1 | 2> | undefined;
|
|
14
|
+
render(value: string | typeof nothing | typeof noChange | undefined | null): typeof noChange | typeof nothing | TemplateResult<1 | 2> | null | undefined;
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* Renders the result as HTML, rather than text.
|
|
19
18
|
*
|
|
19
|
+
* The values `undefined`, `null`, and `nothing`, will all result in no content
|
|
20
|
+
* (empty string) being rendered.
|
|
21
|
+
*
|
|
20
22
|
* Note, this is unsafe to use with any user-provided input that hasn't been
|
|
21
23
|
* sanitized or escaped, as it may lead to cross-site-scripting
|
|
22
24
|
* vulnerabilities.
|
|
23
25
|
*/
|
|
24
|
-
export declare const unsafeHTML: (value: string | typeof noChange | typeof nothing) => import("../directive.js").DirectiveResult<typeof UnsafeHTMLDirective>;
|
|
26
|
+
export declare const unsafeHTML: (value: string | typeof noChange | typeof nothing | null | undefined) => import("../directive.js").DirectiveResult<typeof UnsafeHTMLDirective>;
|
|
25
27
|
//# sourceMappingURL=unsafe-html.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsafe-html.d.ts","sourceRoot":"","sources":["../../src/directives/unsafe-html.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAY,SAAS,EAAE,QAAQ,EAAW,MAAM,iBAAiB,CAAC;AAIzE,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,MAAM,CAAC,aAAa,SAAgB;IACpC,MAAM,CAAC,UAAU,SAAe;IAEhC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,eAAe,CAAC,CAAiB;gBAE7B,QAAQ,EAAE,QAAQ;IAW9B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,OAAO,GAAG,OAAO,QAAQ;
|
|
1
|
+
{"version":3,"file":"unsafe-html.d.ts","sourceRoot":"","sources":["../../src/directives/unsafe-html.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAY,SAAS,EAAE,QAAQ,EAAW,MAAM,iBAAiB,CAAC;AAIzE,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,MAAM,CAAC,aAAa,SAAgB;IACpC,MAAM,CAAC,UAAU,SAAe;IAEhC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,eAAe,CAAC,CAAiB;gBAE7B,QAAQ,EAAE,QAAQ;IAW9B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,OAAO,GAAG,OAAO,QAAQ,GAAG,SAAS,GAAG,IAAI;CAkC3E;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,gJAAiC,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import{Directive as r,
|
|
2
|
-
import{noChange as i,nothing as t}from"../lit-html.js";
|
|
3
|
-
|
|
1
|
+
import{nothing as t,noChange as i}from"../lit-html.js";import{Directive as r,PartType as s,directive as n}from"../directive.js";
|
|
4
2
|
/**
|
|
5
3
|
* @license
|
|
6
4
|
* Copyright 2017 Google LLC
|
|
7
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
8
|
-
*/class
|
|
6
|
+
*/class e extends r{constructor(i){if(super(i),this.it=t,i.type!==s.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(r){if(r===t||null==r)return this.vt=void 0,this.it=r;if(r===i)return r;if("string"!=typeof r)throw Error(this.constructor.directiveName+"() called with a non-string value");if(r===this.it)return this.vt;this.it=r;const s=[r];return s.raw=s,this.vt={_$litType$:this.constructor.resultType,strings:s,values:[]}}}e.directiveName="unsafeHTML",e.resultType=1;const o=n(e);export{e as UnsafeHTMLDirective,o as unsafeHTML};
|
|
9
7
|
//# sourceMappingURL=unsafe-html.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsafe-html.js","sources":["../src/directives/unsafe-html.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {nothing, TemplateResult, noChange} from '../lit-html.js';\nimport {directive, Directive, PartInfo, PartType} from '../directive.js';\n\nconst HTML_RESULT = 1;\n\nexport class UnsafeHTMLDirective extends Directive {\n static directiveName = 'unsafeHTML';\n static resultType = HTML_RESULT;\n\n private _value: unknown = nothing;\n private _templateResult?: TemplateResult;\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (partInfo.type !== PartType.CHILD) {\n throw new Error(\n `${\n (this.constructor as typeof UnsafeHTMLDirective).directiveName\n }() can only be used in child bindings`\n );\n }\n }\n\n render(value: string | typeof nothing | typeof noChange
|
|
1
|
+
{"version":3,"file":"unsafe-html.js","sources":["../src/directives/unsafe-html.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {nothing, TemplateResult, noChange} from '../lit-html.js';\nimport {directive, Directive, PartInfo, PartType} from '../directive.js';\n\nconst HTML_RESULT = 1;\n\nexport class UnsafeHTMLDirective extends Directive {\n static directiveName = 'unsafeHTML';\n static resultType = HTML_RESULT;\n\n private _value: unknown = nothing;\n private _templateResult?: TemplateResult;\n\n constructor(partInfo: PartInfo) {\n super(partInfo);\n if (partInfo.type !== PartType.CHILD) {\n throw new Error(\n `${\n (this.constructor as typeof UnsafeHTMLDirective).directiveName\n }() can only be used in child bindings`\n );\n }\n }\n\n render(value: string | typeof nothing | typeof noChange | undefined | null) {\n if (value === nothing || value == null) {\n this._templateResult = undefined;\n return (this._value = value);\n }\n if (value === noChange) {\n return value;\n }\n if (typeof value != 'string') {\n throw new Error(\n `${\n (this.constructor as typeof UnsafeHTMLDirective).directiveName\n }() called with a non-string value`\n );\n }\n if (value === this._value) {\n return this._templateResult;\n }\n this._value = value;\n const strings = [value] as unknown as TemplateStringsArray;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (strings as any).raw = strings;\n // WARNING: impersonating a TemplateResult like this is extremely\n // dangerous. Third-party directives should not do this.\n return (this._templateResult = {\n // Cast to a known set of integers that satisfy ResultType so that we\n // don't have to export ResultType and possibly encourage this pattern.\n // This property needs to remain unminified.\n ['_$litType$']: (this.constructor as typeof UnsafeHTMLDirective)\n .resultType as 1 | 2,\n strings,\n values: [],\n });\n }\n}\n\n/**\n * Renders the result as HTML, rather than text.\n *\n * The values `undefined`, `null`, and `nothing`, will all result in no content\n * (empty string) being rendered.\n *\n * Note, this is unsafe to use with any user-provided input that hasn't been\n * sanitized or escaped, as it may lead to cross-site-scripting\n * vulnerabilities.\n */\nexport const unsafeHTML = directive(UnsafeHTMLDirective);\n"],"names":["UnsafeHTMLDirective","Directive","constructor","partInfo","super","this","nothing","type","PartType","CHILD","Error","directiveName","render","value","_templateResult","undefined","_value","noChange","strings","raw","_$litType$","resultType","values","unsafeHTML","directive"],"mappings":";;;;;SAWaA,UAA4BC,EAOvCC,YAAYC,GAEV,GADAC,MAAMD,GAJAE,QAAkBC,EAKpBH,EAASI,OAASC,EAASC,MAC7B,MAAUC,MAELL,KAAKH,YAA2CS,cADnD,yCAONC,OAAOC,GACL,GAAIA,IAAUP,GAAoB,MAATO,EAEvB,OADAR,KAAKS,QAAkBC,EACfV,KAAKW,GAASH,EAExB,GAAIA,IAAUI,EACZ,OAAOJ,EAET,GAAoB,iBAATA,EACT,MAAUH,MAELL,KAAKH,YAA2CS,cADnD,qCAKJ,GAAIE,IAAUR,KAAKW,GACjB,OAAOX,KAAKS,GAEdT,KAAKW,GAASH,EACd,MAAMK,EAAU,CAACL,GAKjB,OAHCK,EAAgBC,IAAMD,EAGfb,KAAKS,GAAkB,CAI7BM,WAAiBf,KAAKH,YACnBmB,WACHH,QAAAA,EACAI,OAAQ,KAhDLtB,gBAAgB,aAChBA,aAJW,QAkEPuB,EAAaC,EAAUxB"}
|
|
@@ -11,11 +11,14 @@ declare class UnsafeSVGDirective extends UnsafeHTMLDirective {
|
|
|
11
11
|
/**
|
|
12
12
|
* Renders the result as SVG, rather than text.
|
|
13
13
|
*
|
|
14
|
+
* The values `undefined`, `null`, and `nothing`, will all result in no content
|
|
15
|
+
* (empty string) being rendered.
|
|
16
|
+
*
|
|
14
17
|
* Note, this is unsafe to use with any user-provided input that hasn't been
|
|
15
18
|
* sanitized or escaped, as it may lead to cross-site-scripting
|
|
16
19
|
* vulnerabilities.
|
|
17
20
|
*/
|
|
18
|
-
export declare const unsafeSVG: (value: string | typeof import("../lit-html.js").noChange | typeof import("../lit-html.js").nothing) => import("../directive.js").DirectiveResult<typeof UnsafeSVGDirective>;
|
|
21
|
+
export declare const unsafeSVG: (value: string | typeof import("../lit-html.js").noChange | typeof import("../lit-html.js").nothing | null | undefined) => import("../directive.js").DirectiveResult<typeof UnsafeSVGDirective>;
|
|
19
22
|
/**
|
|
20
23
|
* The type of the class that powers this directive. Necessary for naming the
|
|
21
24
|
* directive's return type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsafe-svg.d.ts","sourceRoot":"","sources":["../../src/directives/unsafe-svg.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAIrD,cAAM,kBAAmB,SAAQ,mBAAmB;IAClD,
|
|
1
|
+
{"version":3,"file":"unsafe-svg.d.ts","sourceRoot":"","sources":["../../src/directives/unsafe-svg.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAIrD,cAAM,kBAAmB,SAAQ,mBAAmB;IAClD,OAAgB,aAAa,SAAe;IAC5C,OAAgB,UAAU,SAAc;CACzC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,iMAAgC,CAAC;AAEvD;;;GAGG;AACH,YAAY,EAAC,kBAAkB,EAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsafe-svg.js","sources":["../src/directives/unsafe-svg.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {directive} from '../directive.js';\nimport {UnsafeHTMLDirective} from './unsafe-html.js';\n\nconst SVG_RESULT = 2;\n\nclass UnsafeSVGDirective extends UnsafeHTMLDirective {\n static directiveName = 'unsafeSVG';\n static resultType = SVG_RESULT;\n}\n\n/**\n * Renders the result as SVG, rather than text.\n *\n * Note, this is unsafe to use with any user-provided input that hasn't been\n * sanitized or escaped, as it may lead to cross-site-scripting\n * vulnerabilities.\n */\nexport const unsafeSVG = directive(UnsafeSVGDirective);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {UnsafeSVGDirective};\n"],"names":["UnsafeSVGDirective","UnsafeHTMLDirective","unsafeSVG","directive"],"mappings":";;;;;GAWA,MAAMA,UAA2BC,
|
|
1
|
+
{"version":3,"file":"unsafe-svg.js","sources":["../src/directives/unsafe-svg.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {directive} from '../directive.js';\nimport {UnsafeHTMLDirective} from './unsafe-html.js';\n\nconst SVG_RESULT = 2;\n\nclass UnsafeSVGDirective extends UnsafeHTMLDirective {\n static override directiveName = 'unsafeSVG';\n static override resultType = SVG_RESULT;\n}\n\n/**\n * Renders the result as SVG, rather than text.\n *\n * The values `undefined`, `null`, and `nothing`, will all result in no content\n * (empty string) being rendered.\n *\n * Note, this is unsafe to use with any user-provided input that hasn't been\n * sanitized or escaped, as it may lead to cross-site-scripting\n * vulnerabilities.\n */\nexport const unsafeSVG = directive(UnsafeSVGDirective);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type {UnsafeSVGDirective};\n"],"names":["UnsafeSVGDirective","UnsafeHTMLDirective","unsafeSVG","directive"],"mappings":";;;;;GAWA,MAAMA,UAA2BC,GACfD,gBAAgB,YAChBA,aAJC,QAiBNE,EAAYC,EAAUH"}
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
* Copyright 2017 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
-
import { AsyncDirective } from '../async-directive.js';
|
|
7
6
|
import { Part } from '../lit-html.js';
|
|
8
|
-
|
|
9
|
-
declare class UntilDirective extends AsyncDirective {
|
|
10
|
-
private
|
|
11
|
-
private
|
|
7
|
+
import { AsyncDirective } from '../async-directive.js';
|
|
8
|
+
export declare class UntilDirective extends AsyncDirective {
|
|
9
|
+
private __lastRenderedIndex;
|
|
10
|
+
private __values;
|
|
11
|
+
private __weakThis;
|
|
12
|
+
private __pauser;
|
|
12
13
|
render(...args: Array<unknown>): unknown;
|
|
13
14
|
update(_part: Part, args: Array<unknown>): unknown;
|
|
15
|
+
disconnected(): void;
|
|
16
|
+
reconnected(): void;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* Renders one of a series of values, including Promises, to a Part.
|
|
@@ -28,13 +31,14 @@ declare class UntilDirective extends AsyncDirective {
|
|
|
28
31
|
*
|
|
29
32
|
* Example:
|
|
30
33
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
34
|
+
* ```js
|
|
35
|
+
* const content = fetch('./content.txt').then(r => r.text());
|
|
36
|
+
* html`${until(content, html`<span>Loading...</span>`)}`
|
|
37
|
+
* ```
|
|
33
38
|
*/
|
|
34
39
|
export declare const until: (...values: unknown[]) => import("../directive.js").DirectiveResult<typeof UntilDirective>;
|
|
35
40
|
/**
|
|
36
41
|
* The type of the class that powers this directive. Necessary for naming the
|
|
37
42
|
* directive's return type.
|
|
38
43
|
*/
|
|
39
|
-
export type { UntilDirective };
|
|
40
44
|
//# sourceMappingURL=until.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/directives/until.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,IAAI,EAAW,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/directives/until.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,IAAI,EAAW,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AASrD,qBAAa,cAAe,SAAQ,cAAc;IAChD,OAAO,CAAC,mBAAmB,CAAqB;IAChD,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,QAAQ,CAAgB;IAEhC,MAAM,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC;IAIrB,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC;IAuExC,YAAY;IAKZ,WAAW;CAIrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,KAAK,4FAA4B,CAAC;AAE/C;;;GAGG"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import{
|
|
2
|
-
import{isPrimitive as s}from"../directive-helpers.js";
|
|
3
|
-
import{directive as r}from"../directive.js";
|
|
4
|
-
import{noChange as t}from"../lit-html.js";
|
|
5
|
-
|
|
1
|
+
import{noChange as t}from"../lit-html.js";import{directive as s}from"../directive.js";import{isPrimitive as i}from"../directive-helpers.js";import{AsyncDirective as r}from"../async-directive.js";import{PseudoWeakRef as e,Pauser as o}from"./private-async-helpers.js";
|
|
6
2
|
/**
|
|
7
3
|
* @license
|
|
8
4
|
* Copyright 2017 Google LLC
|
|
9
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
10
|
-
*/const
|
|
6
|
+
*/const n=t=>!i(t)&&"function"==typeof t.then;class h extends r{constructor(){super(...arguments),this._$Cft=1073741823,this._$Cwt=[],this._$CG=new e(this),this._$CK=new o}render(...s){var i;return null!==(i=s.find((t=>!n(t))))&&void 0!==i?i:t}update(s,i){const r=this._$Cwt;let e=r.length;this._$Cwt=i;const o=this._$CG,h=this._$CK;this.isConnected||this.disconnected();for(let t=0;t<i.length&&!(t>this._$Cft);t++){const s=i[t];if(!n(s))return this._$Cft=t,s;t<e&&s===r[t]||(this._$Cft=1073741823,e=0,Promise.resolve(s).then((async t=>{for(;h.get();)await h.get();const i=o.deref();if(void 0!==i){const r=i._$Cwt.indexOf(s);r>-1&&r<i._$Cft&&(i._$Cft=r,i.setValue(t))}})))}return t}disconnected(){this._$CG.disconnect(),this._$CK.pause()}reconnected(){this._$CG.reconnect(this),this._$CK.resume()}}const c=s(h);export{h as UntilDirective,c as until};
|
|
11
7
|
//# sourceMappingURL=until.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.js","sources":["../src/directives/until.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {Part, noChange} from '../lit-html.js';\nimport {directive} from '../directive.js';\nimport {isPrimitive} from '../directive-helpers.js';\nimport {AsyncDirective} from '../async-directive.js';\n\nconst isPromise = (x: unknown) => {\n return !isPrimitive(x) && typeof (x as {then?: unknown}).then === 'function';\n};\n// Effectively infinity, but a SMI.\nconst _infinity =
|
|
1
|
+
{"version":3,"file":"until.js","sources":["../src/directives/until.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {Part, noChange} from '../lit-html.js';\nimport {directive} from '../directive.js';\nimport {isPrimitive} from '../directive-helpers.js';\nimport {AsyncDirective} from '../async-directive.js';\nimport {Pauser, PseudoWeakRef} from './private-async-helpers.js';\n\nconst isPromise = (x: unknown) => {\n return !isPrimitive(x) && typeof (x as {then?: unknown}).then === 'function';\n};\n// Effectively infinity, but a SMI.\nconst _infinity = 0x3fffffff;\n\nexport class UntilDirective extends AsyncDirective {\n private __lastRenderedIndex: number = _infinity;\n private __values: unknown[] = [];\n private __weakThis = new PseudoWeakRef(this);\n private __pauser = new Pauser();\n\n render(...args: Array<unknown>) {\n return args.find((x) => !isPromise(x)) ?? noChange;\n }\n\n override update(_part: Part, args: Array<unknown>) {\n const previousValues = this.__values;\n let previousLength = previousValues.length;\n this.__values = args;\n\n const weakThis = this.__weakThis;\n const pauser = this.__pauser;\n\n // If our initial render occurs while disconnected, ensure that the pauser\n // and weakThis are in the disconnected state\n if (!this.isConnected) {\n this.disconnected();\n }\n\n for (let i = 0; i < args.length; i++) {\n // If we've rendered a higher-priority value already, stop.\n if (i > this.__lastRenderedIndex) {\n break;\n }\n\n const value = args[i];\n\n // Render non-Promise values immediately\n if (!isPromise(value)) {\n this.__lastRenderedIndex = i;\n // Since a lower-priority value will never overwrite a higher-priority\n // synchronous value, we can stop processing now.\n return value;\n }\n\n // If this is a Promise we've already handled, skip it.\n if (i < previousLength && value === previousValues[i]) {\n continue;\n }\n\n // We have a Promise that we haven't seen before, so priorities may have\n // changed. Forget what we rendered before.\n this.__lastRenderedIndex = _infinity;\n previousLength = 0;\n\n // Note, the callback avoids closing over `this` so that the directive\n // can be gc'ed before the promise resolves; instead `this` is retrieved\n // from `weakThis`, which can break the hard reference in the closure when\n // the directive disconnects\n Promise.resolve(value).then(async (result: unknown) => {\n // If we're disconnected, wait until we're (maybe) reconnected\n // The while loop here handles the case that the connection state\n // thrashes, causing the pauser to resume and then get re-paused\n while (pauser.get()) {\n await pauser.get();\n }\n // If the callback gets here and there is no `this`, it means that the\n // directive has been disconnected and garbage collected and we don't\n // need to do anything else\n const _this = weakThis.deref();\n if (_this !== undefined) {\n const index = _this.__values.indexOf(value);\n // If state.values doesn't contain the value, we've re-rendered without\n // the value, so don't render it. Then, only render if the value is\n // higher-priority than what's already been rendered.\n if (index > -1 && index < _this.__lastRenderedIndex) {\n _this.__lastRenderedIndex = index;\n _this.setValue(result);\n }\n }\n });\n }\n\n return noChange;\n }\n\n override disconnected() {\n this.__weakThis.disconnect();\n this.__pauser.pause();\n }\n\n override reconnected() {\n this.__weakThis.reconnect(this);\n this.__pauser.resume();\n }\n}\n\n/**\n * Renders one of a series of values, including Promises, to a Part.\n *\n * Values are rendered in priority order, with the first argument having the\n * highest priority and the last argument having the lowest priority. If a\n * value is a Promise, low-priority values will be rendered until it resolves.\n *\n * The priority of values can be used to create placeholder content for async\n * data. For example, a Promise with pending content can be the first,\n * highest-priority, argument, and a non_promise loading indicator template can\n * be used as the second, lower-priority, argument. The loading indicator will\n * render immediately, and the primary content will render when the Promise\n * resolves.\n *\n * Example:\n *\n * ```js\n * const content = fetch('./content.txt').then(r => r.text());\n * html`${until(content, html`<span>Loading...</span>`)}`\n * ```\n */\nexport const until = directive(UntilDirective);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\n// export type {UntilDirective};\n"],"names":["isPromise","x","isPrimitive","then","UntilDirective","AsyncDirective","constructor","this","PseudoWeakRef","Pauser","render","args","find","noChange","update","_part","previousValues","__values","previousLength","length","weakThis","__weakThis","pauser","__pauser","isConnected","disconnected","i","__lastRenderedIndex","value","Promise","resolve","async","result","get","_this","deref","undefined","index","indexOf","setValue","disconnect","pause","reconnected","reconnect","resume","until","directive"],"mappings":";;;;;GAYA,MAAMA,EAAaC,IACTC,EAAYD,IAA8C,mBAAhCA,EAAuBE,WAK9CC,UAAuBC,EAApCC,kCACUC,WAHQ,WAIRA,WAAsB,GACtBA,UAAa,IAAIC,EAAcD,MAC/BA,UAAW,IAAIE,EAEvBC,UAAUC,SACR,iBAAOA,EAAKC,MAAMX,IAAOD,EAAUC,oBAAOY,EAGnCC,OAAOC,EAAaJ,GAC3B,MAAMK,EAAiBT,KAAKU,MAC5B,IAAIC,EAAiBF,EAAeG,OACpCZ,KAAKU,MAAWN,EAEhB,MAAMS,EAAWb,KAAKc,KAChBC,EAASf,KAAKgB,KAIfhB,KAAKiB,aACRjB,KAAKkB,eAGP,IAAK,IAAIC,EAAI,EAAGA,EAAIf,EAAKQ,UAEnBO,EAAInB,KAAKoB,OAFkBD,IAAK,CAMpC,MAAME,EAAQjB,EAAKe,GAGnB,IAAK1B,EAAU4B,GAIb,OAHArB,KAAKoB,MAAsBD,EAGpBE,EAILF,EAAIR,GAAkBU,IAAUZ,EAAeU,KAMnDnB,KAAKoB,MAjDO,WAkDZT,EAAiB,EAMjBW,QAAQC,QAAQF,GAAOzB,MAAK4B,MAAOC,IAIjC,KAAOV,EAAOW,aACNX,EAAOW,MAKf,MAAMC,EAAQd,EAASe,QACvB,QAAcC,IAAVF,EAAqB,CACvB,MAAMG,EAAQH,EAAMjB,MAASqB,QAAQV,GAIjCS,GAAS,GAAKA,EAAQH,EAAMP,QAC9BO,EAAMP,MAAsBU,EAC5BH,EAAMK,SAASP,SAMvB,OAAOnB,EAGAY,eACPlB,KAAKc,KAAWmB,aAChBjC,KAAKgB,KAASkB,QAGPC,cACPnC,KAAKc,KAAWsB,UAAUpC,MAC1BA,KAAKgB,KAASqB,gBAyBLC,EAAQC,EAAU1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"experimental-hydrate.d.ts","sourceRoot":"","sources":["../src/experimental-hydrate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAElD,OAAO,EAAW,aAAa,
|
|
1
|
+
{"version":3,"file":"experimental-hydrate.d.ts","sourceRoot":"","sources":["../src/experimental-hydrate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAElD,OAAO,EAAW,aAAa,EAAO,MAAM,eAAe,CAAC;AA8D5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,OAAO,cACP,OAAO,aACP,OAAO,GAAG,gBAAgB,YAC5B,QAAQ,aAAa,CAAC,SAiEhC,CAAC;AAqPF,eAAO,MAAM,uBAAuB,mBAAoB,cAAc,WASrE,CAAC"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import{isPrimitive as n,
|
|
2
|
-
import{PartType as r}from"./directive.js";
|
|
3
|
-
import{_Σ as t,noChange as e}from"./lit-html.js";
|
|
4
|
-
|
|
1
|
+
import{noChange as e,_$LH as t}from"./lit-html.js";import{PartType as r}from"./directive.js";import{isPrimitive as n,isTemplateResult as o,isSingleExpression as l}from"./directive-helpers.js";
|
|
5
2
|
/**
|
|
6
3
|
* @license
|
|
7
4
|
* Copyright 2019 Google LLC
|
|
8
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
-
*/const{
|
|
6
|
+
*/const{R:i,D:a,j:s,H:c,Z:d}=t,p=(e,t,r={})=>{if(void 0!==t._$litPart$)throw Error("container already contains a live render");let n,o;const l=[],i=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT,null,!1);let a;for(;null!==(a=i.nextNode());){const t=a.data;if(t.startsWith("lit-part")){if(0===l.length&&void 0!==n)throw Error("there must be only one root part per container");o=f(e,a,l,r),null!=n||(n=o)}else if(t.startsWith("lit-node")){u(a,l,r);const e=a.parentElement;e.hasAttribute("defer-hydration")&&e.removeAttribute("defer-hydration")}else if(t.startsWith("/lit-part")){if(1===l.length&&o!==n)throw Error("internal error");o=h(a,o,l)}}console.assert(void 0!==n,"there should be exactly one root part in a render container"),t._$litPart$=n},f=(t,r,l,d)=>{let p,f;if(0===l.length)f=new c(r,null,void 0,d),p=t;else{const e=l[l.length-1];if("template-instance"===e.type)f=new c(r,null,e.instance,d),e.instance.v.push(f),p=e.result.values[e.instancePartIndex++],e.templatePartIndex++;else if("iterable"===e.type){f=new c(r,null,e.part,d);const t=e.iterator.next();if(t.done)throw p=void 0,e.done=!0,Error("Unhandled shorter than expected iterable");p=t.value,e.part._$AH.push(f)}else f=new c(r,null,e.part,d)}if(p=s(f,p),p===e)l.push({part:f,type:"leaf"});else if(n(p))l.push({part:f,type:"leaf"}),f._$AH=p;else if(o(p)){const e="lit-part "+m(p);if(r.data!==e)throw Error("Hydration value mismatch: Unexpected TemplateResult rendered to part");{const e=c.prototype._$AC(p),t=new i(e,f);l.push({type:"template-instance",instance:t,part:f,templatePartIndex:0,instancePartIndex:0,result:p}),f._$AH=t}}else a(p)?(l.push({part:f,type:"iterable",value:p,iterator:p[Symbol.iterator](),done:!1}),f._$AH=[]):(l.push({part:f,type:"leaf"}),f._$AH=null==p?"":p);return f},h=(e,t,r)=>{if(void 0===t)throw Error("unbalanced part marker");t._$AB=e;const n=r.pop();if("iterable"===n.type&&!n.iterator.next().done)throw Error("unexpected longer than expected iterable");if(r.length>0)return r[r.length-1].part},u=(e,t,n)=>{var o;const i=/lit-node (\d+)/.exec(e.data),a=parseInt(i[1]),c=null!==(o=e.previousSibling)&&void 0!==o?o:e.parentElement,p=t[t.length-1];if("template-instance"!==p.type)throw Error("internal error");{const e=p.instance;for(;;){const t=e._$AD.parts[p.templatePartIndex];if(void 0===t||t.type!==r.ATTRIBUTE&&t.type!==r.ELEMENT||t.index!==a)break;if(t.type===r.ATTRIBUTE){const o=new t.ctor(c,t.name,t.strings,p.instance,n),i=l(o)?p.result.values[p.instancePartIndex]:p.result.values,a=!(o.type===r.EVENT||o.type===r.PROPERTY);o._$AI(i,o,p.instancePartIndex,a),p.instancePartIndex+=t.strings.length-1,e.v.push(o)}else{const t=new d(c,p.instance,n);s(t,p.result.values[p.instancePartIndex++]),e.v.push(t)}p.templatePartIndex++}}},m=e=>{const t=new Uint32Array(2).fill(5381);for(const r of e.strings)for(let e=0;e<r.length;e++)t[e%2]=33*t[e%2]^r.charCodeAt(e);return btoa(String.fromCharCode(...new Uint8Array(t.buffer)))};export{m as digestForTemplateResult,p as hydrate};
|
|
10
7
|
//# sourceMappingURL=experimental-hydrate.js.map
|