diff --git a/package-lock.json b/package-lock.json index e15b44756..3fb33e36e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -220,9 +220,9 @@ } }, "node_modules/@esbuild/android-arm": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.16.tgz", - "integrity": "sha512-baLqRpLe4JnKrUXLJChoTN0iXZH7El/mu58GE3WIA6/H834k0XWvLRmGLG8y8arTRS9hJJibPnF0tiGhmWeZgw==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.17.tgz", + "integrity": "sha512-E6VAZwN7diCa3labs0GYvhEPL2M94WLF8A+czO8hfjREXxba8Ng7nM5VxV+9ihNXIY1iQO1XxUU4P7hbqbICxg==", "cpu": [ "arm" ], @@ -236,9 +236,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.16.tgz", - "integrity": "sha512-QX48qmsEZW+gcHgTmAj+x21mwTz8MlYQBnzF6861cNdQGvj2jzzFjqH0EBabrIa/WVZ2CHolwMoqxVryqKt8+Q==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.17.tgz", + "integrity": "sha512-jaJ5IlmaDLFPNttv0ofcwy/cfeY4bh/n705Tgh+eLObbGtQBK3EPAu+CzL95JVE4nFAliyrnEu0d32Q5foavqg==", "cpu": [ "arm64" ], @@ -252,9 +252,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.16.tgz", - "integrity": "sha512-G4wfHhrrz99XJgHnzFvB4UwwPxAWZaZBOFXh+JH1Duf1I4vIVfuYY9uVLpx4eiV2D/Jix8LJY+TAdZ3i40tDow==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.17.tgz", + "integrity": "sha512-446zpfJ3nioMC7ASvJB1pszHVskkw4u/9Eu8s5yvvsSDTzYh4p4ZIRj0DznSl3FBF0Z/mZfrKXTtt0QCoFmoHA==", "cpu": [ "x64" ], @@ -268,9 +268,9 @@ } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.16.tgz", - "integrity": "sha512-/Ofw8UXZxuzTLsNFmz1+lmarQI6ztMZ9XktvXedTbt3SNWDn0+ODTwxExLYQ/Hod91EZB4vZPQJLoqLF0jvEzA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.17.tgz", + "integrity": "sha512-m/gwyiBwH3jqfUabtq3GH31otL/0sE0l34XKpSIqR7NjQ/XHQ3lpmQHLHbG8AHTGCw8Ao059GvV08MS0bhFIJQ==", "cpu": [ "arm64" ], @@ -284,9 +284,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.16.tgz", - "integrity": "sha512-SzBQtCV3Pdc9kyizh36Ol+dNVhkDyIrGb/JXZqFq8WL37LIyrXU0gUpADcNV311sCOhvY+f2ivMhb5Tuv8nMOQ==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.17.tgz", + "integrity": "sha512-4utIrsX9IykrqYaXR8ob9Ha2hAY2qLc6ohJ8c0CN1DR8yWeMrTgYFjgdeQ9LIoTOfLetXjuCu5TRPHT9yKYJVg==", "cpu": [ "x64" ], @@ -300,9 +300,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.16.tgz", - "integrity": "sha512-ZqftdfS1UlLiH1DnS2u3It7l4Bc3AskKeu+paJSfk7RNOMrOxmeFDhLTMQqMxycP1C3oj8vgkAT6xfAuq7ZPRA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.17.tgz", + "integrity": "sha512-4PxjQII/9ppOrpEwzQ1b0pXCsFLqy77i0GaHodrmzH9zq2/NEhHMAMJkJ635Ns4fyJPFOlHMz4AsklIyRqFZWA==", "cpu": [ "arm64" ], @@ -316,9 +316,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.16.tgz", - "integrity": "sha512-rHV6zNWW1tjgsu0dKQTX9L0ByiJHHLvQKrWtnz8r0YYJI27FU3Xu48gpK2IBj1uCSYhJ+pEk6Y0Um7U3rIvV8g==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.17.tgz", + "integrity": "sha512-lQRS+4sW5S3P1sv0z2Ym807qMDfkmdhUYX30GRBURtLTrJOPDpoU0kI6pVz1hz3U0+YQ0tXGS9YWveQjUewAJw==", "cpu": [ "x64" ], @@ -332,9 +332,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.16.tgz", - "integrity": "sha512-n4O8oVxbn7nl4+m+ISb0a68/lcJClIbaGAoXwqeubj/D1/oMMuaAXmJVfFlRjJLu/ZvHkxoiFJnmbfp4n8cdSw==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.17.tgz", + "integrity": "sha512-biDs7bjGdOdcmIk6xU426VgdRUpGg39Yz6sT9Xp23aq+IEHDb/u5cbmu/pAANpDB4rZpY/2USPhCA+w9t3roQg==", "cpu": [ "arm" ], @@ -348,9 +348,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.16.tgz", - "integrity": "sha512-8yoZhGkU6aHu38WpaM4HrRLTFc7/VVD9Q2SvPcmIQIipQt2I/GMTZNdEHXoypbbGao5kggLcxg0iBKjo0SQYKA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.17.tgz", + "integrity": "sha512-2+pwLx0whKY1/Vqt8lyzStyda1v0qjJ5INWIe+d8+1onqQxHLLi3yr5bAa4gvbzhZqBztifYEu8hh1La5+7sUw==", "cpu": [ "arm64" ], @@ -364,9 +364,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.16.tgz", - "integrity": "sha512-9ZBjlkdaVYxPNO8a7OmzDbOH9FMQ1a58j7Xb21UfRU29KcEEU3VTHk+Cvrft/BNv0gpWJMiiZ/f4w0TqSP0gLA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.17.tgz", + "integrity": "sha512-IBTTv8X60dYo6P2t23sSUYym8fGfMAiuv7PzJ+0LcdAndZRzvke+wTVxJeCq4WgjppkOpndL04gMZIFvwoU34Q==", "cpu": [ "ia32" ], @@ -380,9 +380,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.16.tgz", - "integrity": "sha512-TIZTRojVBBzdgChY3UOG7BlPhqJz08AL7jdgeeu+kiObWMFzGnQD7BgBBkWRwOtKR1i2TNlO7YK6m4zxVjjPRQ==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.17.tgz", + "integrity": "sha512-WVMBtcDpATjaGfWfp6u9dANIqmU9r37SY8wgAivuKmgKHE+bWSuv0qXEFt/p3qXQYxJIGXQQv6hHcm7iWhWjiw==", "cpu": [ "loong64" ], @@ -396,9 +396,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.16.tgz", - "integrity": "sha512-UPeRuFKCCJYpBbIdczKyHLAIU31GEm0dZl1eMrdYeXDH+SJZh/i+2cAmD3A1Wip9pIc5Sc6Kc5cFUrPXtR0XHA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.17.tgz", + "integrity": "sha512-2kYCGh8589ZYnY031FgMLy0kmE4VoGdvfJkxLdxP4HJvWNXpyLhjOvxVsYjYZ6awqY4bgLR9tpdYyStgZZhi2A==", "cpu": [ "mips64el" ], @@ -412,9 +412,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.16.tgz", - "integrity": "sha512-io6yShgIEgVUhExJejJ21xvO5QtrbiSeI7vYUnr7l+v/O9t6IowyhdiYnyivX2X5ysOVHAuyHW+Wyi7DNhdw6Q==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.17.tgz", + "integrity": "sha512-KIdG5jdAEeAKogfyMTcszRxy3OPbZhq0PPsW4iKKcdlbk3YE4miKznxV2YOSmiK/hfOZ+lqHri3v8eecT2ATwQ==", "cpu": [ "ppc64" ], @@ -428,9 +428,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.16.tgz", - "integrity": "sha512-WhlGeAHNbSdG/I2gqX2RK2gfgSNwyJuCiFHMc8s3GNEMMHUI109+VMBfhVqRb0ZGzEeRiibi8dItR3ws3Lk+cA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.17.tgz", + "integrity": "sha512-Cj6uWLBR5LWhcD/2Lkfg2NrkVsNb2sFM5aVEfumKB2vYetkA/9Uyc1jVoxLZ0a38sUhFk4JOVKH0aVdPbjZQeA==", "cpu": [ "riscv64" ], @@ -444,9 +444,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.16.tgz", - "integrity": "sha512-gHRReYsJtViir63bXKoFaQ4pgTyah4ruiMRQ6im9YZuv+gp3UFJkNTY4sFA73YDynmXZA6hi45en4BGhNOJUsw==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.17.tgz", + "integrity": "sha512-lK+SffWIr0XsFf7E0srBjhpkdFVJf3HEgXCwzkm69kNbRar8MhezFpkIwpk0qo2IOQL4JE4mJPJI8AbRPLbuOQ==", "cpu": [ "s390x" ], @@ -460,9 +460,9 @@ } }, "node_modules/@esbuild/linux-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.16.tgz", - "integrity": "sha512-mfiiBkxEbUHvi+v0P+TS7UnA9TeGXR48aK4XHkTj0ZwOijxexgMF01UDFaBX7Q6CQsB0d+MFNv9IiXbIHTNd4g==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.17.tgz", + "integrity": "sha512-XcSGTQcWFQS2jx3lZtQi7cQmDYLrpLRyz1Ns1DzZCtn898cWfm5Icx/DEWNcTU+T+tyPV89RQtDnI7qL2PObPg==", "cpu": [ "x64" ], @@ -476,9 +476,9 @@ } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.16.tgz", - "integrity": "sha512-n8zK1YRDGLRZfVcswcDMDM0j2xKYLNXqei217a4GyBxHIuPMGrrVuJ+Ijfpr0Kufcm7C1k/qaIrGy6eG7wvgmA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.17.tgz", + "integrity": "sha512-RNLCDmLP5kCWAJR+ItLM3cHxzXRTe4N00TQyQiimq+lyqVqZWGPAvcyfUBM0isE79eEZhIuGN09rAz8EL5KdLA==", "cpu": [ "x64" ], @@ -492,9 +492,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.16.tgz", - "integrity": "sha512-lEEfkfsUbo0xC47eSTBqsItXDSzwzwhKUSsVaVjVji07t8+6KA5INp2rN890dHZeueXJAI8q0tEIfbwVRYf6Ew==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.17.tgz", + "integrity": "sha512-PAXswI5+cQq3Pann7FNdcpSUrhrql3wKjj3gVkmuz6OHhqqYxKvi6GgRBoaHjaG22HV/ZZEgF9TlS+9ftHVigA==", "cpu": [ "x64" ], @@ -508,9 +508,9 @@ } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.16.tgz", - "integrity": "sha512-jlRjsuvG1fgGwnE8Afs7xYDnGz0dBgTNZfgCK6TlvPH3Z13/P5pi6I57vyLE8qZYLrGVtwcm9UbUx1/mZ8Ukag==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.17.tgz", + "integrity": "sha512-V63egsWKnx/4V0FMYkr9NXWrKTB5qFftKGKuZKFIrAkO/7EWLFnbBZNM1CvJ6Sis+XBdPws2YQSHF1Gqf1oj/Q==", "cpu": [ "x64" ], @@ -524,9 +524,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.16.tgz", - "integrity": "sha512-TzoU2qwVe2boOHl/3KNBUv2PNUc38U0TNnzqOAcgPiD/EZxT2s736xfC2dYQbszAwo4MKzzwBV0iHjhfjxMimg==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.17.tgz", + "integrity": "sha512-YtUXLdVnd6YBSYlZODjWzH+KzbaubV0YVd6UxSfoFfa5PtNJNaW+1i+Hcmjpg2nEe0YXUCNF5bkKy1NnBv1y7Q==", "cpu": [ "arm64" ], @@ -540,9 +540,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.16.tgz", - "integrity": "sha512-B8b7W+oo2yb/3xmwk9Vc99hC9bNolvqjaTZYEfMQhzdpBsjTvZBlXQ/teUE55Ww6sg//wlcDjOaqldOKyigWdA==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.17.tgz", + "integrity": "sha512-yczSLRbDdReCO74Yfc5tKG0izzm+lPMYyO1fFTcn0QNwnKmc3K+HdxZWLGKg4pZVte7XVgcFku7TIZNbWEJdeQ==", "cpu": [ "ia32" ], @@ -556,9 +556,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.16.tgz", - "integrity": "sha512-xJ7OH/nanouJO9pf03YsL9NAFQBHd8AqfrQd7Pf5laGyyTt/gToul6QYOA/i5i/q8y9iaM5DQFNTgpi995VkOg==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.17.tgz", + "integrity": "sha512-FNZw7H3aqhF9OyRQbDDnzUApDXfC1N6fgBhkqEO2jvYCJ+DxMTfZVqg3AX0R1khg1wHTBRD5SdcibSJ+XF6bFg==", "cpu": [ "x64" ], @@ -1069,9 +1069,9 @@ } }, "node_modules/esbuild": { - "version": "0.17.16", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.16.tgz", - "integrity": "sha512-aeSuUKr9aFVY9Dc8ETVELGgkj4urg5isYx8pLf4wlGgB0vTFjxJQdHnNH6Shmx4vYYrOTLCHtRI5i1XZ9l2Zcg==", + "version": "0.17.17", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.17.tgz", + "integrity": "sha512-/jUywtAymR8jR4qsa2RujlAF7Krpt5VWi72Q2yuLD4e/hvtNcFQ0I1j8m/bxq238pf3/0KO5yuXNpuLx8BE1KA==", "dev": true, "hasInstallScript": true, "bin": { @@ -1081,28 +1081,28 @@ "node": ">=12" }, "optionalDependencies": { - "@esbuild/android-arm": "0.17.16", - "@esbuild/android-arm64": "0.17.16", - "@esbuild/android-x64": "0.17.16", - "@esbuild/darwin-arm64": "0.17.16", - "@esbuild/darwin-x64": "0.17.16", - "@esbuild/freebsd-arm64": "0.17.16", - "@esbuild/freebsd-x64": "0.17.16", - "@esbuild/linux-arm": "0.17.16", - "@esbuild/linux-arm64": "0.17.16", - "@esbuild/linux-ia32": "0.17.16", - "@esbuild/linux-loong64": "0.17.16", - "@esbuild/linux-mips64el": "0.17.16", - "@esbuild/linux-ppc64": "0.17.16", - "@esbuild/linux-riscv64": "0.17.16", - "@esbuild/linux-s390x": "0.17.16", - "@esbuild/linux-x64": "0.17.16", - "@esbuild/netbsd-x64": "0.17.16", - "@esbuild/openbsd-x64": "0.17.16", - "@esbuild/sunos-x64": "0.17.16", - "@esbuild/win32-arm64": "0.17.16", - "@esbuild/win32-ia32": "0.17.16", - "@esbuild/win32-x64": "0.17.16" + "@esbuild/android-arm": "0.17.17", + "@esbuild/android-arm64": "0.17.17", + "@esbuild/android-x64": "0.17.17", + "@esbuild/darwin-arm64": "0.17.17", + "@esbuild/darwin-x64": "0.17.17", + "@esbuild/freebsd-arm64": "0.17.17", + "@esbuild/freebsd-x64": "0.17.17", + "@esbuild/linux-arm": "0.17.17", + "@esbuild/linux-arm64": "0.17.17", + "@esbuild/linux-ia32": "0.17.17", + "@esbuild/linux-loong64": "0.17.17", + "@esbuild/linux-mips64el": "0.17.17", + "@esbuild/linux-ppc64": "0.17.17", + "@esbuild/linux-riscv64": "0.17.17", + "@esbuild/linux-s390x": "0.17.17", + "@esbuild/linux-x64": "0.17.17", + "@esbuild/netbsd-x64": "0.17.17", + "@esbuild/openbsd-x64": "0.17.17", + "@esbuild/sunos-x64": "0.17.17", + "@esbuild/win32-arm64": "0.17.17", + "@esbuild/win32-ia32": "0.17.17", + "@esbuild/win32-x64": "0.17.17" } }, "node_modules/escape-string-regexp": { @@ -2307,9 +2307,9 @@ } }, "node_modules/style-mod": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.0.2.tgz", - "integrity": "sha512-C4myMmRTO8iaC5Gg+N1ftK2WT4eXUTMAa+HEFPPrfVeO/NtqLTtAmV1HbqnuGtLwCek44Ra76fdGUkSqjiMPcQ==" + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.0.3.tgz", + "integrity": "sha512-78Jv8kYJdjbvRwwijtCevYADfsI0lGzYJe4mMFdceO8l75DFFDoqBhR1jVDicDRRaX4//g1u9wKeo+ztc2h1Rw==" }, "node_modules/supports-color": { "version": "5.5.0", diff --git a/resources/js/code/index.mjs b/resources/js/code/index.mjs index b5080963b..60b4df997 100644 --- a/resources/js/code/index.mjs +++ b/resources/js/code/index.mjs @@ -1,8 +1,9 @@ import {EditorView, keymap} from "@codemirror/view"; import {copyTextToClipboard} from "../services/clipboard.js" -import {viewer, editor} from "./setups.js"; -import {createView, updateViewLanguage} from "./views.js"; +import {viewerExtensions, editorExtensions} from "./setups.js"; +import {createView} from "./views.js"; +import {SimpleEditorInterface} from "./simple-editor-interface.js"; /** * Highlight pre elements on a page @@ -45,10 +46,12 @@ function highlightElem(elem) { const ev = createView({ parent: wrapper, doc: content, - extensions: viewer(wrapper), + extensions: viewerExtensions(wrapper), }); - setMode(ev, langName, content); + const editor = new SimpleEditorInterface(ev); + editor.setMode(langName, content); + elem.remove(); addCopyIcon(ev); } @@ -88,31 +91,25 @@ function addCopyIcon(editorView) { /** * Create a CodeMirror instance for showing inside the WYSIWYG editor. - * Manages a textarea element to hold code content. + * Manages a textarea element to hold code content. * @param {HTMLElement} cmContainer * @param {ShadowRoot} shadowRoot * @param {String} content * @param {String} language - * @returns {EditorView} + * @returns {SimpleEditorInterface} */ export function wysiwygView(cmContainer, shadowRoot, content, language) { - // Monkey-patch so that the container document window "CSSStyleSheet" is used instead of the outer window document. - // Needed otherwise codemirror fails to apply styles due to a window mismatch when creating a new "CSSStyleSheet" instance. - // Opened: https://github.com/codemirror/dev/issues/1133 - const originalCSSStyleSheetReference = window.CSSStyleSheet; - window.CSSStyleSheet = cmContainer.ownerDocument.defaultView.CSSStyleSheet; - const ev = createView({ parent: cmContainer, doc: content, - extensions: viewer(cmContainer), + extensions: viewerExtensions(cmContainer), root: shadowRoot, }); - window.CSSStyleSheet = originalCSSStyleSheetReference; - setMode(ev, language, content); + const editor = new SimpleEditorInterface(ev); + editor.setMode(language, content); - return ev; + return editor; } @@ -120,36 +117,44 @@ export function wysiwygView(cmContainer, shadowRoot, content, language) { * Create a CodeMirror instance to show in the WYSIWYG pop-up editor * @param {HTMLElement} elem * @param {String} modeSuggestion - * @returns {*} + * @returns {SimpleEditorInterface} */ export function popupEditor(elem, modeSuggestion) { const content = elem.textContent; + const config = { + parent: elem.parentElement, + doc: content, + extensions: [ + ...editorExtensions(elem.parentElement), + EditorView.updateListener.of((v) => { + if (v.docChanged) { + // textArea.value = v.state.doc.toString(); + } + }), + ], + }; - return CodeMirror(function(elt) { - elem.parentNode.insertBefore(elt, elem); - elem.style.display = 'none'; - }, { - value: content, - mode: getMode(modeSuggestion, content), - lineNumbers: true, - lineWrapping: false, - theme: getTheme() - }); + // Create editor, hide original input + const editor = new SimpleEditorInterface(createView(config)); + editor.setMode(modeSuggestion, content); + elem.style.display = 'none'; + + return editor; } /** * Create an inline editor to replace the given textarea. * @param {HTMLTextAreaElement} textArea * @param {String} mode - * @returns {EditorView} + * @returns {SimpleEditorInterface} */ export function inlineEditor(textArea, mode) { const content = textArea.value; const config = { - parent: textArea.parentNode, + parent: textArea.parentElement, doc: content, extensions: [ - ...editor(textArea.parentElement), + ...editorExtensions(textArea.parentElement), EditorView.updateListener.of((v) => { if (v.docChanged) { textArea.value = v.state.doc.toString(); @@ -160,31 +165,11 @@ export function inlineEditor(textArea, mode) { // Create editor view, hide original input const ev = createView(config); - setMode(ev, mode, content); + const editor = new SimpleEditorInterface(ev); + editor.setMode(mode, content); textArea.style.display = 'none'; - return ev; -} - -/** - * Set the language mode of a codemirror EditorView. - * - * @param {EditorView} ev - * @param {string} modeSuggestion - * @param {string} content - */ -export function setMode(ev, modeSuggestion, content) { - updateViewLanguage(ev, modeSuggestion, content); -} - -/** - * Set the content of a cm instance. - * @param {EditorView} ev - * @param codeContent - */ -export function setContent(ev, codeContent) { - const doc = ev.state.doc; - doc.replace(0, doc.length, codeContent); + return editor; } /** @@ -193,15 +178,15 @@ export function setContent(ev, codeContent) { * @param {function} onChange * @param {object} domEventHandlers * @param {Array} keyBindings - * @returns {*} + * @returns {EditorView} */ export function markdownEditor(elem, onChange, domEventHandlers, keyBindings) { const content = elem.textContent; const config = { - parent: elem.parentNode, + parent: elem.parentElement, doc: content, extensions: [ - ...editor(elem.parentElement), + ...editorExtensions(elem.parentElement), EditorView.updateListener.of((v) => { onChange(v); }), @@ -215,7 +200,7 @@ export function markdownEditor(elem, onChange, domEventHandlers, keyBindings) { // Create editor view, hide original input const ev = createView(config); - setMode(ev, 'markdown', ''); + (new SimpleEditorInterface(ev)).setMode('markdown', ''); elem.style.display = 'none'; return ev; diff --git a/resources/js/code/setups.js b/resources/js/code/setups.js index 842917285..46041a0a2 100644 --- a/resources/js/code/setups.js +++ b/resources/js/code/setups.js @@ -26,7 +26,7 @@ function common(parentEl) { * @param {Element} parentEl * @return {*[]} */ -export function viewer(parentEl) { +export function viewerExtensions(parentEl) { return [ ...common(parentEl), keymap.of([ @@ -40,7 +40,7 @@ export function viewer(parentEl) { * @param {Element} parentEl * @return {*[]} */ -export function editor(parentEl) { +export function editorExtensions(parentEl) { return [ ...common(parentEl), history(), diff --git a/resources/js/code/simple-editor-interface.js b/resources/js/code/simple-editor-interface.js new file mode 100644 index 000000000..6e94ca767 --- /dev/null +++ b/resources/js/code/simple-editor-interface.js @@ -0,0 +1,46 @@ +import {updateViewLanguage} from "./views"; + + +export class SimpleEditorInterface { + /** + * @param {EditorView} editorView + */ + constructor(editorView) { + this.ev = editorView; + } + + /** + * Get the contents of an editor instance. + * @return {string} + */ + getContent() { + return this.ev.state.doc.toString(); + } + + /** + * Set the contents of an editor instance. + * @param content + */ + setContent(content) { + const doc = this.ev.state.doc; + this.ev.dispatch({ + changes: {from: 0, to: doc.length, insert: content} + }); + } + + /** + * Return focus to the editor instance. + */ + focus() { + this.ev.focus(); + } + + /** + * Set the language mode of the editor instance. + * @param {String} mode + * @param {String} content + */ + setMode(mode, content = '') { + updateViewLanguage(this.ev, mode, content); + } +} \ No newline at end of file diff --git a/resources/js/components/code-editor.js b/resources/js/components/code-editor.js index 09818f844..0188eb250 100644 --- a/resources/js/components/code-editor.js +++ b/resources/js/components/code-editor.js @@ -4,6 +4,15 @@ import {Component} from "./component"; export class CodeEditor extends Component { + /** + * @type {null|SimpleEditorInterface} + */ + editor = null; + + callback = null; + history = {}; + historyKey = 'code_history'; + setup() { this.container = this.$refs.container; this.popup = this.$el; @@ -16,10 +25,6 @@ export class CodeEditor extends Component { this.historyList = this.$refs.historyList; this.favourites = new Set(this.$opts.favourites.split(',')); - this.callback = null; - this.editor = null; - this.history = {}; - this.historyKey = 'code_history'; this.setupListeners(); this.setupFavourites(); } @@ -45,7 +50,7 @@ export class CodeEditor extends Component { event.preventDefault(); const historyTime = elem.dataset.time; if (this.editor) { - this.editor.setValue(this.history[historyTime]); + this.editor.setContent(this.history[historyTime]); } }); } @@ -104,19 +109,18 @@ export class CodeEditor extends Component { save() { if (this.callback) { - this.callback(this.editor.getValue(), this.languageInput.value); + this.callback(this.editor.getContent(), this.languageInput.value); } this.hide(); } - open(code, language, callback) { + async open(code, language, callback) { this.languageInput.value = language; this.callback = callback; - this.show() - .then(() => this.languageInputChange(language)) - .then(() => window.importVersioned('code')) - .then(Code => Code.setContent(this.editor, code)); + await this.show(); + this.languageInputChange(language); + this.editor.setContent(code); } async show() { @@ -146,8 +150,7 @@ export class CodeEditor extends Component { } async updateEditorMode(language) { - const Code = await window.importVersioned('code'); - Code.setMode(this.editor, language, this.editor.getValue()); + this.editor.setMode(language, this.editor.getContent()); } languageInputChange(language) { @@ -176,7 +179,7 @@ export class CodeEditor extends Component { addHistory() { if (!this.editor) return; - const code = this.editor.getValue(); + const code = this.editor.getContent(); if (!code) return; // Stop if we'd be storing the same as the last item diff --git a/resources/js/wysiwyg/plugin-codeeditor.js b/resources/js/wysiwyg/plugin-codeeditor.js index 7eff5c279..9a7b3fe65 100644 --- a/resources/js/wysiwyg/plugin-codeeditor.js +++ b/resources/js/wysiwyg/plugin-codeeditor.js @@ -36,6 +36,12 @@ function defineCodeBlockCustomElement(editor) { const win = doc.defaultView; class CodeBlockElement extends win.HTMLElement { + + /** + * @type {?SimpleEditorInterface} + */ + editor = null; + constructor() { super(); this.attachShadow({mode: 'open'}); @@ -63,11 +69,9 @@ function defineCodeBlockCustomElement(editor) { } setContent(content, language) { - if (this.cm) { - importVersioned('code').then(Code => { - Code.setContent(this.cm, content); - Code.setMode(this.cm, language, content); - }); + if (this.editor) { + this.editor.setContent(content); + this.editor.setMode(language, content); } let pre = this.querySelector('pre'); @@ -98,7 +102,7 @@ function defineCodeBlockCustomElement(editor) { connectedCallback() { const connectedTime = Date.now(); - if (this.cm) { + if (this.editor) { return; } @@ -109,14 +113,14 @@ function defineCodeBlockCustomElement(editor) { this.style.height = `${height}px`; const container = this.shadowRoot.querySelector('.CodeMirrorContainer'); - const renderCodeMirror = (Code) => { - this.cm = Code.wysiwygView(container, this.shadowRoot, content, this.getLanguage()); + const renderEditor = (Code) => { + this.editor = Code.wysiwygView(container, this.shadowRoot, content, this.getLanguage()); setTimeout(() => this.style.height = null, 12); }; window.importVersioned('code').then((Code) => { const timeout = (Date.now() - connectedTime < 20) ? 20 : 0; - setTimeout(() => renderCodeMirror(Code), timeout); + setTimeout(() => renderEditor(Code), timeout); }); } diff --git a/resources/sass/_components.scss b/resources/sass/_components.scss index 825501364..4e6a8d731 100644 --- a/resources/sass/_components.scss +++ b/resources/sass/_components.scss @@ -730,7 +730,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { .code-editor-main { flex: 1; min-width: 0; - .CodeMirror { + .cm-editor { margin-bottom: 0; z-index: 1; max-width: 100%;